/Users/lyon/j4p/src/ip/gui/dialog/ExpandoLog.java

1    package ip.gui.dialog; 
2     
3    import java.awt.*; 
4    import java.awt.event.ActionEvent; 
5    import java.awt.event.ActionListener; 
6     
7     
8    public class ExpandoLog extends 
9            Dialog implements ActionListener { 
10    
11       private TextField fields[]; 
12       private Label labels[]; 
13       public Button cancelButton = new Button("Cancel"); 
14       public Button setButton = new Button("Set"); 
15       private String userInput; 
16       private int fieldSize; 
17    
18       private static int colSpace = 5; 
19       private static int rowSpace = 10; 
20       private static int colNum = 2; 
21    
22       private int rowNum; 
23    
24       private Panel inputPanel = new Panel(); 
25    
26       public ExpandoLog( 
27               Frame frame, 
28               String title, 
29               String prompts[], 
30               String defaults[], 
31               int _fieldSize) { 
32    
33           super(frame, title, false); 
34           initialize(prompts, defaults, _fieldSize); 
35           pack(); 
36           show(); 
37       } 
38    
39       private void initialize( 
40               String prompts[], 
41               String defaults[], 
42               int _fieldSize) { 
43    
44           fieldSize = _fieldSize; 
45           rowNum = prompts.length; 
46           labels = new Label[rowNum]; 
47           fields = new TextField[rowNum]; 
48    
49           inputPanel.setLayout(new 
50                   GridLayout( 
51                           rowNum, 
52                           colNum, 
53                           colSpace, 
54                           rowSpace)); 
55           for (int i = 0; i < rowNum; i++) { 
56               labels[i] = new Label(prompts[i]); 
57               if (defaults == null) 
58                   fields[i] = new TextField(fieldSize); 
59               else 
60                   fields[i] = new TextField(defaults[i], fieldSize); 
61               inputPanel.add(labels[i]); 
62               inputPanel.add(fields[i]); 
63           } 
64           add("Center", inputPanel); 
65    
66    
67           buttonPanel(); 
68    
69       } 
70    
71    
72       private void buttonPanel() { 
73           Panel p2 = new Panel(); 
74           p2.setLayout(new FlowLayout(FlowLayout.RIGHT)); 
75    
76           p2.add(cancelButton); 
77           p2.add(setButton); 
78           cancelButton.addActionListener(this); 
79           setButton.addActionListener(this); 
80           add("South", p2); 
81    
82           pack(); 
83           show(); 
84       } 
85    
86       public void printUserInput() { 
87           String userInput[] = getUserInput(); 
88           for (int i = 0; i < fields.length; i++) { 
89               userInput[i] = fields[i].getText(); 
90               System.out.println(userInput[i]); 
91           } 
92       } 
93    
94       public String[] getUserInput() { 
95           String userInput[] = new String[fields.length]; 
96           for (int i = 0; i < fields.length; i++) 
97               userInput[i] = fields[i].getText(); 
98           return userInput; 
99       } 
100   
101      public static void main(String args[]) { 
102          String title = "Rotation Dialog"; 
103          int fieldSize = 6; 
104   
105          String prompts[] = { 
106              "X (degs):", 
107              "Y (degs):", 
108              "Z (degs):" 
109          }; 
110   
111          String defaults[] = { 
112              "1.0", 
113              "2.0", 
114              "3.0" 
115          }; 
116   
117          ExpandoLog xpol = new 
118                  ExpandoLog( 
119                          new Frame(), 
120                          title, 
121                          prompts, 
122                          defaults, 
123                          fieldSize); 
124      } 
125   
126      public void actionPerformed(ActionEvent e) { 
127          Button b = (Button) e.getSource(); 
128          if (b == cancelButton) setVisible(false); 
129      } 
130   
131  } 
132   
133   
134   
135   
136   
137   
138   
139   
140