/Users/lyon/j4p/src/ip/hak/ListDialog.java

1    package ip.hak; 
2     
3     
4    import java.awt.*; 
5    import java.awt.event.*; 
6    import java.util.Vector; 
7     
8     
9    public class ListDialog 
10    
11           extends Dialog 
12    
13           implements WindowListener, ActionListener, ItemListener { 
14    
15       Vector v; 
16    
17       List fileList; 
18    
19       Button okButton, cancelButton; 
20    
21       TextField tf; 
22    
23       String filename = null; 
24    
25    
26       public ListDialog(Frame parent, String title, Vector vl) { 
27    
28           super(parent, title, true); 
29    
30           v = vl; 
31    
32           addWindowListener(this); 
33    
34           setSize(300, 300); 
35    
36           init(); 
37    
38           setVisible(true); 
39    
40       } 
41    
42    
43       public void init() { 
44    
45           setLayout(null); 
46    
47           setResizable(false); 
48    
49           fileList = new List(6, false); 
50    
51           fileList.setSize(240, 200); 
52    
53           fileList.setLocation(30, 30); 
54    
55           add(fileList); 
56    
57           fileList.addItemListener(this); 
58    
59    
60           tf = new TextField(); 
61    
62           tf.setSize(240, 20); 
63    
64           tf.setLocation(30, 240); 
65    
66           add(tf); 
67    
68    
69           okButton = new Button("Select"); 
70    
71           okButton.setSize(60, 20); 
72    
73           okButton.setLocation(60, 270); 
74    
75           okButton.addActionListener(this); 
76    
77           add(okButton); 
78    
79    
80           cancelButton = new Button("Cancel"); 
81    
82           cancelButton.setSize(60, 20); 
83    
84           cancelButton.setLocation(180, 270); 
85    
86           cancelButton.addActionListener(this); 
87    
88           add(cancelButton); 
89    
90    
91       } 
92    
93    
94       public void itemStateChanged(ItemEvent e) { 
95    
96           filename = fileList.getSelectedItem(); 
97    
98           tf.setText(filename); 
99    
100      } 
101   
102   
103      public void actionPerformed(ActionEvent e) { 
104   
105          if (e.getSource() == okButton) { 
106   
107              if (tf.getText() == null) { 
108   
109                  return; 
110   
111              } 
112   
113              setVisible(false); 
114   
115              return; 
116   
117          } 
118   
119   
120          if (e.getSource() == cancelButton) { 
121   
122              setVisible(false); 
123   
124              return; 
125   
126          } 
127   
128      } 
129   
130   
131      public void windowOpened(WindowEvent e) { 
132      } 
133   
134   
135      public void windowClosing(WindowEvent e) { 
136          dispose(); 
137      } 
138   
139   
140      public void windowClosed(WindowEvent e) { 
141      } 
142   
143   
144      public void windowIconified(WindowEvent e) { 
145      } 
146   
147   
148      public void windowDeiconified(WindowEvent e) { 
149      } 
150   
151   
152      public void windowActivated(WindowEvent e) { 
153      } 
154   
155   
156      public void windowDeactivated(WindowEvent e) { 
157      } 
158   
159  } 
160   
161