This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI.java
414 lines (328 loc) · 11.3 KB
/
GUI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
class GUI2 extends JFrame
{
private JRadioButton res, par;
private ButtonGroup group;
private JLabel logo_name, delivery_type, date_time, table_no, name, address, contact, toppings_label, quantity_label;
private ImageIcon logo;
private JTextField table_no_tf, name_tf, address_tf, contact_tf;
private JPanel input_panel, delivery_panel, toppings_panel, toppings2_panel, quantity_panel, initial_panel, buttons_panel;
private JPanel top1_panel, top2_panel;
private JCheckBox top_onion, top_mushroom, top_broccoli, top_corn, top_capsicum, top_cheese;
private JComboBox quantity_box;
String date;
public float rate = 80; //base rate is Rs.80
private JLabel quantity_op_label, quantity_op, rate_label, rate_op_label;
private JButton print, clear, calculate;
private ImageIcon print_icon, clear_icon;
private JLabel table_no_op, name_op, address_op, contact_op;
String table_no_str, name_str, address_str, contact_str;
private JLabel table_no2, name2, address2, contact2;
private JLabel date_time2;
private JLabel logo_name2;
public GUI2()
{
super("Pizza Palace");
setLayout(new FlowLayout(FlowLayout.CENTER, 30, 15));
logo = new ImageIcon("pizza.png");
logo_name = new JLabel("Pizza Palace", logo, 0);
initial_panel = new JPanel();
initial_panel.setLayout(new GridLayout(2, 1));
JOptionPane.showMessageDialog(new JFrame(), "Welcome to Pizza Palace!", "Pizza Palace", JOptionPane.PLAIN_MESSAGE, logo);
//Logo Icon and Name
logo = new ImageIcon("pizza.png");
logo_name = new JLabel("Pizza Palace", logo, 0);
initial_panel.add(logo_name);
//Date and Time
date = new SimpleDateFormat("EEEE yyyy-MM-dd hh:mm:ss a zzz").format(new Date());
date_time = new JLabel(date);
initial_panel.add(date_time);
add(initial_panel);
}
public void Input()
{
input_panel = new JPanel();
input_panel.setLayout(new GridLayout(5, 2, 5, 5));
delivery_panel = new JPanel();
delivery_panel.setLayout(new GridLayout(1, 3));
//Delivery Type
delivery_type = new JLabel("Delivery Type:");
// delivery_panel.add(delivery_type);
res = new JRadioButton("in-Restaurant");
res.setActionCommand("res");
par = new JRadioButton("Parcel");
par.setActionCommand("par");
group = new ButtonGroup();
group.add(res);
group.add(par);
delivery_panel.add(res);
delivery_panel.add(par);
// add(delivery_panel);
input_panel.add(delivery_type);
input_panel.add(delivery_panel);
//Table Number
table_no = new JLabel("Table Number");
table_no_tf = new JTextField("", 5);
input_panel.add(table_no);
input_panel.add(table_no_tf);
//Parcel Details
name = new JLabel("Name");
address = new JLabel("Address");
contact = new JLabel("Contact Number");
name_tf = new JTextField("", 10);
address_tf = new JTextField("", 20);
contact_tf = new JTextField("", 10);
input_panel.add(name);
input_panel.add(name_tf);
input_panel.add(address);
input_panel.add(address_tf);
input_panel.add(contact);
input_panel.add(contact_tf);
add(input_panel);
// Disable Extra Labels & TextFields depending on RadioButton Selected
res.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent arg0)
{
if(res.isSelected())
{
name.setEnabled(false);
address.setEnabled(false);
contact.setEnabled(false);
name_tf.setEditable(false);
address_tf.setEditable(false);
contact_tf.setEditable(false);
name_tf.setEnabled(false);
address_tf.setEnabled(false);
contact_tf.setEnabled(false);
table_no.setEnabled(true);
table_no_tf.setEnabled(true);
table_no_tf.setEditable(true);
}
}
});
par.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent arg0)
{
if(par.isSelected())
{
table_no.setEnabled(false);
table_no_tf.setEnabled(false);
table_no_tf.setEditable(false);
name.setEnabled(true);
address.setEnabled(true);
contact.setEnabled(true);
name_tf.setEditable(true);
address_tf.setEditable(true);
contact_tf.setEditable(true);
name_tf.setEnabled(true);
address_tf.setEnabled(true);
contact_tf.setEnabled(true);
}
}
});
}
public void Toppings()
{
top1_panel = new JPanel();
top1_panel.setLayout(new GridLayout(1, 3));
top2_panel = new JPanel();
top2_panel.setLayout(new GridLayout(1, 3));
toppings_panel = new JPanel();
toppings_panel.setLayout(new GridLayout(2, 1));
toppings2_panel = new JPanel();
toppings2_panel.setLayout(new GridLayout(2, 1));
toppings_label = new JLabel("Toppings:");
top_onion = new JCheckBox("Onion", false);
top_mushroom = new JCheckBox("Mushroom", false);
top_broccoli = new JCheckBox("Broccoli", false);
top_corn = new JCheckBox("Corn", false);
top_capsicum = new JCheckBox("Capsicum", false);
top_cheese = new JCheckBox("Cheese", false);
/* ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
AbstractButton abstractButton = (AbstractButton) actionEvent.getSource();
boolean selected = abstractButton.getModel().isSelected();
if(selected)
rate = rate + 15;
}
};
top_onion.addActionListener(actionListener);
top_mushroom.addActionListener(actionListener);
top_broccoli.addActionListener(actionListener);
top_corn.addActionListener(actionListener);
top_capsicum.addActionListener(actionListener);
top_cheese.addActionListener(actionListener);
*/
ItemListener itemListener = new ItemListener()
{
public void itemStateChanged(ItemEvent itemEvent)
{
AbstractButton abstractButton = (AbstractButton) itemEvent.getSource();
int state = itemEvent.getStateChange();
if(state == ItemEvent.SELECTED)
{
rate = rate + 15;
}
}
};
top_onion.addItemListener(itemListener);
top_mushroom.addItemListener(itemListener);
top_broccoli.addItemListener(itemListener);
top_corn.addItemListener(itemListener);
top_capsicum.addItemListener(itemListener);
top_cheese.addItemListener(itemListener);
top1_panel.add(top_onion);
top1_panel.add(top_mushroom);
top1_panel.add(top_broccoli);
top2_panel.add(top_corn);
top2_panel.add(top_capsicum);
top2_panel.add(top_cheese);
toppings_panel.add(top1_panel);
toppings_panel.add(top2_panel);
toppings2_panel.add(toppings_label);
toppings2_panel.add(toppings_panel);
add(toppings2_panel);
}
public void Quantity()
{
quantity_label = new JLabel("Quantity: ");
quantity_op_label = new JLabel("Quantity: ");
quantity_op = new JLabel();
quantity_panel = new JPanel();
quantity_panel.setLayout(new GridLayout(2, 2));
String[] quantity = {"1", "2", "3", "4", "5"};
JComboBox<String>quantity_box = new JComboBox<String>();
for(int i = 0; i < quantity.length; i++)
quantity_box.addItem(quantity[i]);
quantity_box.setSelectedIndex(0);
quantity_panel.add(quantity_label);
quantity_panel.add(quantity_box);
quantity_box.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
quantity_op.setText((String)((JComboBox)e.getSource()).getSelectedItem());
}
});
add(quantity_panel);
}
public void Output()
{
print_icon = new ImageIcon("print.png");
clear_icon = new ImageIcon("clear.png");
buttons_panel = new JPanel();
buttons_panel.setLayout(new GridLayout(1, 2, 50, 10));
table_no2 = new JLabel("Table No.: ");
name2 = new JLabel("Name: ");
address2 = new JLabel("Address: ");
contact2= new JLabel("Contact Number: ");
String rate_str;
rate_str = Float.toString(rate);
rate_label = new JLabel("Rate: ");
rate_op_label = new JLabel(rate_str);
print = new JButton("Print");
print.setRolloverIcon(print_icon);
print.setRolloverEnabled(true);
clear = new JButton("Clear");
buttons_panel.add(print);
buttons_panel.add(clear);
add(buttons_panel);
clear.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
table_no_tf.setText("");
name_tf.setText("");
address_tf.setText("");
contact_tf.setText("");
group.clearSelection();
name.setEnabled(true);
address.setEnabled(true);
contact.setEnabled(true);
name_tf.setEditable(true);
address_tf.setEditable(true);
contact_tf.setEditable(true);
name_tf.setEnabled(true);
address_tf.setEnabled(true);
contact_tf.setEnabled(true);
table_no.setEnabled(true);
table_no_tf.setEnabled(true);
table_no_tf.setEditable(true);
top_broccoli.setSelected(false);
top_capsicum.setSelected(false);
top_cheese.setSelected(false);
top_corn.setSelected(false);
top_mushroom.setSelected(false);
top_onion.setSelected(false);
}
});
print.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String rate_str;
rate_str = Float.toString(rate);
rate_label = new JLabel("Rate: ");
rate_op_label = new JLabel(rate_str);
JFrame output = new JFrame();
output.setLayout(new GridLayout(8, 2));
logo_name2 = new JLabel("Pizza Palace", logo, 0);
output.add(logo_name2);
date = new SimpleDateFormat("E yyyy-MM-dd HH:mm:ss").format(new Date());
date_time2 = new JLabel(date);
output.add(date_time2);
table_no_str = table_no_tf.getText();
name_str = name_tf.getText();
address_str = address_tf.getText();
contact_str = contact_tf.getText();
table_no_op = new JLabel(table_no_str);
name_op = new JLabel(name_str);
address_op = new JLabel(address_str);
contact_op = new JLabel(contact_str);
output.add(table_no2);
output.add(table_no_op);
output.add(name2);
output.add(name_op);
output.add(address2);
output.add(address_op);
output.add(contact2);
output.add(contact_op);
output.add(rate_label);
output.add(rate_op_label);
output.add(quantity_op_label);
output.add(quantity_op);
output.pack();
output.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
output.setLocationRelativeTo(null);
// output.setSize(100, 100);
output.setVisible(true);
JOptionPane.showMessageDialog(null, "Your Order Has Been Placed!");
}
});
}
}
class GUI
{
public static void main(String[] args)
{
GUI2 gui_obj = new GUI2();
gui_obj.Input();
gui_obj.Toppings();
gui_obj.Quantity();
gui_obj.Output();
gui_obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui_obj.setLocationByPlatform(true);
gui_obj.setSize(575,600);
gui_obj.setVisible(true);
}
}