1 // SpecTcl generated class Demo2, version 1.2
2 
3 import java.awt.*;
4 import java.awt.event.*;
5 import javax.swing.*;
6 import javax.swing.event.*;
7 
8 public class Demo2 extends Helper implements ActionListener {
9 
10 // a slot to hold an arbitrary object pointer that can
11 // be filled in by the app. and referenced in actions
12 private Object arg;
13 
14 private JPanel frame_1;
15 private JButton button_2;
16 private JLabel label_1;
17 private JButton button_3;
18 private JButton button_4;
19 private JButton button_1;
20 private JLabel label_2;
21 protected JTextField name;
22 private JLabel label_3;
23 protected JTextField phone;
24 protected JLabel message;
25 
26 //methods to support form introspection
27 private static String names[] = {
28 	"frame_1","button_2","label_1","button_3","button_4","button_1","label_2","name","label_3","phone","message",
29 };
getNames()30 public String[] getNames() {
31 	return names;
32 }
33 
34 //There should be an easier way to do this
getWidgets()35 public Object[] getWidgets() {
36 	Object[] list = new Object[11];
37 	list[0] = frame_1;
38 	list[1] = button_2;
39 	list[2] = label_1;
40 	list[3] = button_3;
41 	list[4] = button_4;
42 	list[5] = button_1;
43 	list[6] = label_2;
44 	list[7] = name;
45 	list[8] = label_3;
46 	list[9] = phone;
47 	list[10] = message;
48 	return list;
49 }
50 
51 // Application specific widget data
52 private static String check_private[] = {
53 	null, null, null, null, null, null, null, "a*", null, "999-9999", null,
54 };
check()55 public String[] check() {
56 	return check_private;
57 }
58 
59 
init()60 public void init() {
61 
62 	// main panel
63 	GridBagLayout grid = new GridBagLayout();
64 	int rowHeights[] = {0,30,30,30,5,30,13};
65 	int columnWidths[] = {0,30,30};
66 	double rowWeights[] = {0.0,0.0,0.0,0.0,1.0,0.0,0.0};
67 	double columnWeights[] = {0.0,0.0,1.0};
68 	grid.rowHeights = rowHeights;
69 	grid.columnWidths = columnWidths;
70 	grid.rowWeights = rowWeights;
71 	grid.columnWeights = columnWeights;
72 
73 	// container frame_1 in this.
74 	GridBagLayout frame_1_grid = new GridBagLayout();
75 	int frame_1_rowHeights[] = {0,30};
76 	int frame_1_columnWidths[] = {0,30,30,30,5,30};
77 	double frame_1_rowWeights[] = {0.0,0.0};
78 	double frame_1_columnWeights[] = {0.0,0.0,0.0,0.0,1.0,0.0};
79 	frame_1_grid.rowHeights = frame_1_rowHeights;
80 	frame_1_grid.columnWidths = frame_1_columnWidths;
81 	frame_1_grid.rowWeights = frame_1_rowWeights;
82 	frame_1_grid.columnWeights = frame_1_columnWeights;
83 
84 	frame_1 = new JPanel();
85 	this.getContentPane().add(frame_1);
86 
87 	button_2 = new JButton();
88 	button_2.addActionListener(this);
89 	button_2.setText("get");
90 	frame_1.add(button_2);
91 
92 	label_1 = new JLabel();
93 	label_1.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 14));
94 	label_1.setText("Sample database app");
95 	this.getContentPane().add(label_1);
96 
97 	button_3 = new JButton();
98 	button_3.addActionListener(this);
99 	button_3.setText("set");
100 	frame_1.add(button_3);
101 
102 	button_4 = new JButton();
103 	button_4.addActionListener(this);
104 	button_4.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 12));
105 	button_4.setText("save");
106 	frame_1.add(button_4);
107 
108 	button_1 = new JButton();
109 	button_1.addActionListener(this);
110 	button_1.setText("quit");
111 	frame_1.add(button_1);
112 
113 	label_2 = new JLabel();
114 	label_2.setText("name");
115 	this.getContentPane().add(label_2);
116 
117 	name = new JTextField(20);
118 	name.addActionListener(this);
119 	this.getContentPane().add(name);
120 
121 	label_3 = new JLabel();
122 	label_3.setText("phone");
123 	this.getContentPane().add(label_3);
124 
125 	phone = new JTextField(20);
126 	phone.addActionListener(this);
127 	this.getContentPane().add(phone);
128 
129 	message = new JLabel();
130 	message.setText(".");
131 	this.getContentPane().add(message);
132 
133 	// Geometry management
134 	GridBagConstraints con = new GridBagConstraints();
135 	reset(con);
136 	con.gridx = 1;
137 	con.gridy = 5;
138 	con.gridwidth = 2;
139 	con.anchor = GridBagConstraints.CENTER;
140 	con.fill = GridBagConstraints.HORIZONTAL;
141 	grid.setConstraints(frame_1, con);
142 
143 	reset(con);
144 	con.gridx = 1;
145 	con.gridy = 1;
146 	con.anchor = GridBagConstraints.CENTER;
147 	con.fill = GridBagConstraints.NONE;
148 	frame_1_grid.setConstraints(button_2, con);
149 
150 	reset(con);
151 	con.gridx = 1;
152 	con.gridy = 1;
153 	con.gridwidth = 2;
154 	con.anchor = GridBagConstraints.CENTER;
155 	con.fill = GridBagConstraints.NONE;
156 	grid.setConstraints(label_1, con);
157 
158 	reset(con);
159 	con.gridx = 2;
160 	con.gridy = 1;
161 	con.anchor = GridBagConstraints.CENTER;
162 	con.fill = GridBagConstraints.NONE;
163 	frame_1_grid.setConstraints(button_3, con);
164 
165 	reset(con);
166 	con.gridx = 3;
167 	con.gridy = 1;
168 	con.anchor = GridBagConstraints.CENTER;
169 	con.fill = GridBagConstraints.NONE;
170 	frame_1_grid.setConstraints(button_4, con);
171 
172 	reset(con);
173 	con.gridx = 5;
174 	con.gridy = 1;
175 	con.anchor = GridBagConstraints.CENTER;
176 	con.fill = GridBagConstraints.NONE;
177 	frame_1_grid.setConstraints(button_1, con);
178 
179 	reset(con);
180 	con.gridx = 1;
181 	con.gridy = 2;
182 	con.anchor = GridBagConstraints.EAST;
183 	con.fill = GridBagConstraints.NONE;
184 	grid.setConstraints(label_2, con);
185 
186 	reset(con);
187 	con.gridx = 2;
188 	con.gridy = 2;
189 	con.anchor = GridBagConstraints.CENTER;
190 	con.fill = GridBagConstraints.HORIZONTAL;
191 	grid.setConstraints(name, con);
192 
193 	reset(con);
194 	con.gridx = 1;
195 	con.gridy = 3;
196 	con.anchor = GridBagConstraints.EAST;
197 	con.fill = GridBagConstraints.NONE;
198 	grid.setConstraints(label_3, con);
199 
200 	reset(con);
201 	con.gridx = 2;
202 	con.gridy = 3;
203 	con.anchor = GridBagConstraints.CENTER;
204 	con.fill = GridBagConstraints.HORIZONTAL;
205 	grid.setConstraints(phone, con);
206 
207 	reset(con);
208 	con.gridx = 1;
209 	con.gridy = 6;
210 	con.gridwidth = 2;
211 	con.anchor = GridBagConstraints.CENTER;
212 	con.fill = GridBagConstraints.HORIZONTAL;
213 	grid.setConstraints(message, con);
214 
215 
216 	// Resize behavior management and parent heirarchy
217 	this.getContentPane().setLayout(grid);
218 	//Set the Background Color
219 	this.getContentPane().setBackground(new Color(59293/256,60333/256,53052/256));
220 	frame_1.setLayout(frame_1_grid);
221 	//Set the Background Color
222 	frame_1.setBackground(new Color(59293/256,60333/256,53052/256));
223 
224 	// Give the application a chance to do its initialization
225 	super.init();
226 }
227 
actionPerformed(ActionEvent event)228 public void actionPerformed(ActionEvent event) {
229 	if (event.getSource() == button_2) {
230 		getData();
231 	}
232 	if (event.getSource() == button_3) {
233 		db.put(name.getText(),phone.getText());
234 	}
235 	if (event.getSource() == button_4) {
236 		db.write();message.setText("saved");
237 	}
238 	if (event.getSource() == button_1) {
239 		System.exit(0);
240 	}
241 }
242 
243 // code sourced from Demo2.include.java
244 //  This code is inserted into the SpecJava class
245 //  directly.  It comes from the <project>.include.java
246 //  file in the current directory.  It can be editted either
247 //  with your favorite text editor, or via the "edit code"
248 //  option of the edit menu.
249 
250 
main(String[] args)251 public static void main(String[] args) {
252     JFrame f = new JFrame("Demo2 Test");
253     Demo2 win = new Demo2();
254     f.addWindowListener(
255        new WindowAdapter()
256        {
257              public void windowClosing(WindowEvent e)
258              {
259                  System.exit(0);
260              }
261         }
262     );
263     win.init();
264     f.getContentPane().add("Center", win);
265     f.pack();
266     f.setVisible(true);
267 }
268 
reset(GridBagConstraints con)269 private void reset(GridBagConstraints con) {
270     con.gridx = GridBagConstraints.RELATIVE;
271     con.gridy = GridBagConstraints.RELATIVE;
272     con.gridwidth = 1;
273     con.gridheight = 1;
274 
275     con.weightx = 0;
276     con.weighty = 0;
277     con.anchor = GridBagConstraints.CENTER;
278     con.fill = GridBagConstraints.NONE;
279 
280     con.insets = new Insets(0, 0, 0, 0);
281     con.ipadx = 0;
282     con.ipady = 0;
283 }
284 
285 }
286