KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > notification > whiteboard > SelectDialog


1 package demo.notification.whiteboard;
2
3 import java.util.Enumeration JavaDoc;
4 import java.awt.Frame JavaDoc;
5
6 /**
7  * @author
8  * @version
9  */

10
11 public class SelectDialog extends java.awt.Dialog JavaDoc {
12
13     /** Initializes the Form */
14     public SelectDialog(Frame JavaDoc parentFrame, WorkgroupController controller) {
15         super (parentFrame, "Select a Whiteboard");
16         initComponents ();
17     controller_ = controller;
18         pack ();
19         refresh();
20     }
21
22     private void initComponents () {
23         addWindowListener (new java.awt.event.WindowAdapter JavaDoc () {
24                                public void windowClosing (java.awt.event.WindowEvent JavaDoc evt) {
25                                    closeDialog (evt);
26                                }
27                            }
28                           );
29         setLayout (new java.awt.BorderLayout JavaDoc ());
30
31         panel1 = new java.awt.Panel JavaDoc ();
32         panel1.setName ("buttonPanel");
33         panel1.setLayout (new java.awt.FlowLayout JavaDoc ());
34
35         joinButton = new java.awt.Button JavaDoc ();
36         joinButton.setLabel ("Join");
37         joinButton.setName ("joinButton");
38         joinButton.addActionListener (new java.awt.event.ActionListener JavaDoc () {
39                                           public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
40                                               joinButtonActionPerformed (evt);
41                                           }
42                                       }
43                                      );
44         panel1.add (joinButton);
45
46         refreshButton = new java.awt.Button JavaDoc ();
47         refreshButton.setLabel ("Refresh");
48         refreshButton.setName ("refreshButton");
49         refreshButton.addActionListener (new java.awt.event.ActionListener JavaDoc () {
50                                              public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
51                                                  refreshButtonActionPerformed (evt);
52                                              }
53                                          }
54                                         );
55         panel1.add (refreshButton);
56
57         add (panel1, "South");
58
59         availableList = new java.awt.List JavaDoc ();
60         availableList.addActionListener( new java.awt.event.ActionListener JavaDoc() {
61                                              public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
62                                                  selectionTField.setText(availableList.getSelectedItem() );
63                                              }
64                                          }
65                                        );
66         availableList.setName ("availableList");
67         add (availableList, "Center");
68
69         selectionTField = new java.awt.TextField JavaDoc ();
70         add (selectionTField, "North");
71
72     }
73
74     private void refreshButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
75         refresh();
76     }
77
78     private void joinButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
79         String JavaDoc result = selectionTField.getText();
80         if ( result.length() > 0 ) {
81             controller_.selectWhiteboard(result);
82             close();
83         }
84     }
85
86     void refresh() {
87         availableList.removeAll();
88         String JavaDoc[] _list = controller_.getListOfWhiteboards();
89     for (int x=0; x<_list.length; ++x) {
90         availableList.add(_list[x]);
91     }
92     }
93
94     /** Closes the dialog */
95     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {
96         close();
97     }
98
99     void close() {
100         setVisible (false);
101         dispose ();
102     }
103
104     private java.awt.Panel JavaDoc panel1;
105     private java.awt.Button JavaDoc joinButton;
106     private java.awt.Button JavaDoc refreshButton;
107     private java.awt.List JavaDoc availableList;
108     private java.awt.TextField JavaDoc selectionTField;
109     private WorkgroupController controller_;
110 }
111
Popular Tags