-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderMenu.java
More file actions
486 lines (449 loc) · 18.1 KB
/
OrderMenu.java
File metadata and controls
486 lines (449 loc) · 18.1 KB
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
// Jason Jasper
// David Martin-Vaquero
// Jared Mclaren
// Regine Villongco
// Chemen Wong
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* IS 380 Final Project - Restaurant Point of Sale program.
* @author Jason Jasper, David Martin-Vaquero, Jared Mclaren, Regine Villongco, Chemen Wong
* @version 0.1.0
*
* This is the Order Window GUI component. This class controls all the functionality of being able to select a
* order function, which consists of:
* Add - Adds an item(s) to an Order.
* Sub - Subtracts (deletes) an item(s) from an Order.
* Comp - Comps an item(s) for an order. This is where the item is basically given for free to the customer.
* Note - This adds a note/special instructions to an order, i.e. Mild/Medium/Hot
* Sub-Total - This calculates a current sub-total for an order.
* Cash Out - This tenders the total amount for the order, archives the order data (for reporting), and destroys
* the Order object associated with a table so a new one can be made.
*
* Once a function is selected, a table can then be selected, opening up the appropriate GUI window for that function.
*
*/
public class OrderMenu extends JFrame {
private String functionSelected;
/**
Constructor for order menu.
*/
public OrderMenu() {
initComponents();
}
/**
Method for table button's action.
@param ActionEvent object generated.
*/
private void tableButtonActionPerformed(ActionEvent e) {
String tableString = e.getActionCommand();
int tableNum = Integer.parseInt(tableString);
System.out.println(functionSelected + " function on Table " + tableNum);
if (this.functionSelected.equals("Add")) {
if (RestaurantPOS.isTableAvailable(tableNum)) {
// Action to add to empty table.
System.out.println("Table " + tableNum+ " is available.");
}
else { System.out.println("Table " + tableNum + " has an order"); }
// Create item menu.
ItemMenu itemMenu = new ItemMenu(tableNum);
itemMenu.setVisible(true);
}
if (this.functionSelected.equals("Sub")) {
if (RestaurantPOS.isTableAvailable(tableNum)) {
System.out.println("Table "+tableNum+" does NOT have an order to sub an item.");
displayNoOrderDialog(tableNum, "Sub");
}
// Action to create sub menu.
else {
RemoveItemMenu subMenu = new RemoveItemMenu(tableNum);
subMenu.setVisible(true);
}
}
if (this.functionSelected.equals("Comp")) {
if (RestaurantPOS.isTableAvailable(tableNum)) {
System.out.println("Table "+tableNum+" does NOT have an order to comp an item.");
displayNoOrderDialog(tableNum, "Comp");
}
else {
// Action to create comp menu.
CompItemMenu compMenu = new CompItemMenu(tableNum);
compMenu.setVisible(true);
}
}
if (this.functionSelected.equals("Note")) {
if (RestaurantPOS.isTableAvailable(tableNum)) {
System.out.println("Table "+tableNum+" does NOT have an order to put a note on.");
displayNoOrderDialog(tableNum, "Note");
}
else { System.out.println("Table " + tableNum + " opening note window");
// Create note menu.
OrderNoteMenu noteMenu = new OrderNoteMenu(tableNum);
noteMenu.setVisible(true);
}
}
if (this.functionSelected.equals("Subtotal")) {
if (RestaurantPOS.isTableAvailable(tableNum)) {
// Check if table is in use.
System.out.println("Table "+tableNum+" does NOT have an order to subtotal.");
displayNoOrderDialog(tableNum, "Subtotal");
}
else {
// Action to get subtotal
System.out.println("Table " + tableNum + " getting subtotal!");
RestaurantPOS.tableArray[tableNum - 1].getSubtotal(tableNum);
SubTotalMenu subTotalMenu = new SubTotalMenu(tableNum);
subTotalMenu.setVisible(true);
}
}
if (this.functionSelected.equals("Close")) {
if (RestaurantPOS.isTableAvailable(tableNum)) {
// Check if table is in use.
System.out.println("Table "+tableNum+" does NOT have an order to close.");
displayNoOrderDialog(tableNum, "Cash Out");
}
else {
// Create cash out menu.
System.out.println("Table " + tableNum + " closing out order!");
CashOutMenu cashOutMenu = new CashOutMenu(tableNum);
cashOutMenu.setVisible(true);
}
}
}
/**
Method to display warning dialog that an order does not exist to perform selected function on.
@param tableNum table number. function function name
*/
private void displayNoOrderDialog(int tableNum, String function) {
JOptionPane.showMessageDialog(null, "Table "+tableNum+" Does NOT have" +
" an order to "+ function, "No Order", JOptionPane.WARNING_MESSAGE);
}
/**
Method for back button's action.
@param ActionEvent object generated.
*/
private void backButtonActionPerformed(ActionEvent e) {
//Using dispose to close window rather than hiding it, this should fix a bug that keeps
//the color coding on the buttons from working more than once.
MainMenu menu = new MainMenu();
menu.setVisible(true);
this.dispose();
}
/**
Method for add button's action.
@param ActionEvent object generated.
*/
private void addbuttonActionPerformed(ActionEvent e) {
this.enableTableButtons();
addButton.setForeground(Color.white);
addButton.setBackground(Color.red );
subButton.setForeground(null);
subButton.setBackground(null);
compButton.setForeground(null);
compButton.setBackground(null);
noteButton.setForeground(null);
noteButton.setBackground(null);
subTotalButton.setForeground(null);
subTotalButton.setBackground(null);
cashOutButton.setForeground(null);
cashOutButton.setBackground(null);
this.functionSelected = "Add";
}
/**
Method for sub button's action.
@param ActionEvent object generated.
*/
private void subButtonActionPerformed(ActionEvent e) {
this.enableTableButtons();
addButton.setForeground(null);
addButton.setBackground(null);
subButton.setForeground(Color.white);
subButton.setBackground(Color.red);
compButton.setForeground(null);
compButton.setBackground(null);
noteButton.setForeground(null);
noteButton.setBackground(null);
subTotalButton.setForeground(null);
subTotalButton.setBackground(null);
cashOutButton.setForeground(null);
cashOutButton.setBackground(null);
this.functionSelected = "Sub";
}
/**
Method for sub button's action.
@param ActionEvent object generated.
*/
private void compButtonActionPerformed(ActionEvent e) {
this.enableTableButtons();
addButton.setForeground(null);
addButton.setBackground(null);
subButton.setForeground(null);
subButton.setBackground(null);
compButton.setForeground(Color.white);
compButton.setBackground(Color.red);
noteButton.setForeground(null);
noteButton.setBackground(null);
subTotalButton.setForeground(null);
subTotalButton.setBackground(null);
cashOutButton.setForeground(null);
cashOutButton.setBackground(null);
this.functionSelected = "Comp";
}
/**
Method for note button's action.
@param ActionEvent object generated.
*/
private void noteButtonActionPerformed(ActionEvent e) {
this.enableTableButtons();
addButton.setForeground(null);
addButton.setBackground(null);
subButton.setForeground(null);
subButton.setBackground(null);
compButton.setForeground(null);
compButton.setBackground(null);
noteButton.setForeground(Color.white);
noteButton.setBackground(Color.red);
subTotalButton.setForeground(null);
subTotalButton.setBackground(null);
cashOutButton.setForeground(null);
cashOutButton.setBackground(null);
this.functionSelected = "Note";
}
/**
Method for subtotal button's action.
@param ActionEvent object generated.
*/
private void subTotalButtonActionPerformed(ActionEvent e) {
this.enableTableButtons();
addButton.setForeground(null);
addButton.setBackground(null);
subButton.setForeground(null);
subButton.setBackground(null);
compButton.setForeground(null);
compButton.setBackground(null);
noteButton.setForeground(null);
noteButton.setBackground(null);
subTotalButton.setForeground(Color.white);
subTotalButton.setBackground(Color.red);
cashOutButton.setForeground(null);
cashOutButton.setBackground(null);
this.functionSelected = "Subtotal";
}
/**
Method for cash out button's action.
@param ActionEvent object generated.
*/
private void cashOutButtonActionPerformed(ActionEvent e) {
this.enableTableButtons();
addButton.setForeground(null);
addButton.setBackground(null);
subButton.setForeground(null);
subButton.setBackground(null);
compButton.setForeground(null);
compButton.setBackground(null);
noteButton.setForeground(null);
noteButton.setBackground(null);
subTotalButton.setForeground(null);
subTotalButton.setBackground(null);
cashOutButton.setForeground(Color.white);
cashOutButton.setBackground(Color.red);
this.functionSelected = "Close";
}
/**
Method to enable table buttons.
*/
private void enableTableButtons() {
tablePanel.setEnabled(true);
table1.setEnabled(true);
table2.setEnabled(true);
table3.setEnabled(true);
table4.setEnabled(true);
table5.setEnabled(true);
table6.setEnabled(true);
table7.setEnabled(true);
table8.setEnabled(true);
table9.setEnabled(true);
}
/**
Method to create labels, panes, and buttons.
*/
private void initComponents() {
label1 = new JLabel();
tablePanel = new JPanel();
table1 = new JButton();
table2 = new JButton();
table3 = new JButton();
table4 = new JButton();
table5 = new JButton();
table6 = new JButton();
table7 = new JButton();
table8 = new JButton();
table9 = new JButton();
hSpacer1 = new JPanel(null);
hSpacer2 = new JPanel(null);
bottomPanel = new JPanel();
operationsPanel = new JPanel();
addButton = new JButton();
subButton = new JButton();
compButton = new JButton();
noteButton = new JButton();
functionsPanel = new JPanel();
backButton = new JButton();
subTotalButton = new JButton();
cashOutButton = new JButton();
//======== this ========
setTitle("Orders");
var contentPane = getContentPane();
contentPane.setLayout(new BorderLayout(10, 10));
//---- label1 ----
label1.setText("Select a Table");
label1.setFont(new Font("Arial", Font.BOLD, 24));
label1.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(label1, BorderLayout.NORTH);
//======== tablePanel ========
{
tablePanel.setPreferredSize(new Dimension(300, 200));
tablePanel.setEnabled(false);
tablePanel.setLayout(new GridLayout(3, 3, 5, 5));
//---- table1 ----
table1.setText("1");
table1.setFont(new Font("Tahoma", Font.PLAIN, 18));
table1.setEnabled(false);
table1.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table1);
//---- table2 ----
table2.setText("2");
table2.setFont(new Font("Tahoma", Font.PLAIN, 18));
table2.setEnabled(false);
table2.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table2);
//---- table3 ----
table3.setText("3");
table3.setFont(new Font("Tahoma", Font.PLAIN, 18));
table3.setEnabled(false);
table3.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table3);
//---- table4 ----
table4.setText("4");
table4.setFont(new Font("Tahoma", Font.PLAIN, 18));
table4.setEnabled(false);
table4.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table4);
//---- table5 ----
table5.setText("5");
table5.setFont(new Font("Tahoma", Font.PLAIN, 18));
table5.setEnabled(false);
table5.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table5);
//---- table6 ----
table6.setText("6");
table6.setFont(new Font("Tahoma", Font.PLAIN, 18));
table6.setEnabled(false);
table6.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table6);
//---- table7 ----
table7.setText("7");
table7.setFont(new Font("Tahoma", Font.PLAIN, 18));
table7.setEnabled(false);
table7.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table7);
//---- table8 ----
table8.setText("8");
table8.setFont(new Font("Tahoma", Font.PLAIN, 18));
table8.setEnabled(false);
table8.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table8);
//---- table9 ----
table9.setText("9");
table9.setFont(new Font("Tahoma", Font.PLAIN, 18));
table9.setEnabled(false);
table9.addActionListener(e -> tableButtonActionPerformed(e));
tablePanel.add(table9);
}
// Add to content pane.
contentPane.add(tablePanel, BorderLayout.CENTER);
contentPane.add(hSpacer1, BorderLayout.WEST);
contentPane.add(hSpacer2, BorderLayout.EAST);
//======== bottomPanel ========
{
bottomPanel.setPreferredSize(new Dimension(1000, 150));
bottomPanel.setLayout(new BorderLayout(5, 5));
//======== operationsPanel ========
{
operationsPanel.setPreferredSize(new Dimension(500, 56));
operationsPanel.setLayout(new GridLayout(2, 1, 10, 10));
//---- addbutton ----
addButton.setText("Add");
addButton.setFont(new Font("Tahoma", Font.PLAIN, 28));
addButton.addActionListener(e -> addbuttonActionPerformed(e));
operationsPanel.add(addButton);
//---- subButton ----
subButton.setText("Sub");
subButton.setFont(new Font("Tahoma", Font.PLAIN, 28));
subButton.addActionListener(e -> subButtonActionPerformed(e));
operationsPanel.add(subButton);
//---- compButton ----
compButton.setText("Comp");
compButton.setFont(new Font("Tahoma", Font.PLAIN, 28));
compButton.addActionListener(e -> compButtonActionPerformed(e));
operationsPanel.add(compButton);
//---- noteButton ----
noteButton.setText("Note");
noteButton.setFont(new Font("Tahoma", Font.PLAIN, 28));
noteButton.addActionListener(e -> noteButtonActionPerformed(e));
operationsPanel.add(noteButton);
}
// Add to bottom panel.
bottomPanel.add(operationsPanel, BorderLayout.CENTER);
//======== functionsPanel ========
{
functionsPanel.setLayout(new GridLayout(1, 3, 10, 0));
//---- backButton ----
backButton.setText("Back");
backButton.setFont(new Font("Tahoma", Font.PLAIN, 28));
backButton.setForeground(Color.red);
backButton.addActionListener(e -> backButtonActionPerformed(e));
functionsPanel.add(backButton);
//---- subTotalButton ----
subTotalButton.setText("Sub-Total");
subTotalButton.setFont(new Font("Tahoma", Font.PLAIN, 28));
subTotalButton.addActionListener(e -> subTotalButtonActionPerformed(e));
functionsPanel.add(subTotalButton);
//---- cashOutButton ----
cashOutButton.setText("Cash Out");
cashOutButton.setFont(new Font("Tahoma", Font.PLAIN, 28));
cashOutButton.addActionListener(e -> cashOutButtonActionPerformed(e));
functionsPanel.add(cashOutButton);
}
bottomPanel.add(functionsPanel, BorderLayout.PAGE_END);
}
// Add to bottom panel to content pane.
contentPane.add(bottomPanel, BorderLayout.SOUTH);
setSize(930, 580);
setLocationRelativeTo(getOwner());
}
private JLabel label1;
private JPanel tablePanel;
private JButton table1;
private JButton table2;
private JButton table3;
private JButton table4;
private JButton table5;
private JButton table6;
private JButton table7;
private JButton table8;
private JButton table9;
private JPanel hSpacer1;
private JPanel hSpacer2;
private JPanel bottomPanel;
private JPanel operationsPanel;
private JButton addButton;
private JButton subButton;
private JButton compButton;
private JButton noteButton;
private JPanel functionsPanel;
private JButton backButton;
private JButton subTotalButton;
private JButton cashOutButton;
}