-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI.java
158 lines (135 loc) · 4.29 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
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* Graphical User Interface for Point of Sale emulator. This class handles only
* initialization and creation of the GUI structure
*
* @author Chae Jubb
* @version 1.0
*
*/
public class GUI {
private GUIController controller;
private JFrame mainGUI;
private JPanel mainPane, posLeft;
private JTextArea orderContents;
private JButton clearOrder, submitOrder;
private JTextField runningTotal;
/**
* Empty Constructor.
*/
public GUI() {
}
/**
* Prompts user for menu source file
*/
public void initGUI() {
String header = "Chae's Fancy POS GUI!";
String message = "Continuing will allow selection of menu source file.";
int n = JOptionPane.showConfirmDialog(null, message, header,
JOptionPane.OK_CANCEL_OPTION);
// continue to allow file to be chosen if "ok"
if (n == JOptionPane.OK_OPTION) {
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"Text Files", "txt");
fileChooser.setFileFilter(filter);
if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(null)) {
this.createGUI(fileChooser.getSelectedFile().getAbsolutePath());
}
// otherwise quit
} else if (n == JOptionPane.CANCEL_OPTION) {
System.exit(0);
}
}
/**
* Creates GUI structure, including panels, buttons, and text areas
*
* @param menuLocation
* String location of the menu source file
*/
private void createGUI(String menuLocation) {
this.controller = new GUIController(this);
this.mainGUI = new JFrame("Chae's Fancy POS GUI!");
this.mainPane = new JPanel(new GridLayout(1, 2));
// create clear order and submit order buttons
JPanel menuModifiers = new JPanel(new GridLayout(1, 2));
this.clearOrder = new JButton("Clear Order");
this.submitOrder = new JButton("Finished Order");
this.clearOrder.setPreferredSize(new Dimension(0, 200));
this.submitOrder.setPreferredSize(new Dimension(0, 200));
this.clearOrder.addActionListener(this.controller);
this.submitOrder.addActionListener(this.controller);
menuModifiers.add(this.submitOrder);
menuModifiers.add(this.clearOrder);
// running list of order
this.orderContents = new JTextArea();
this.orderContents.setEditable(false);
// running total price
this.runningTotal = new JTextField();
this.runningTotal.setEditable(false);
this.runningTotal.setText("TOTAL: $0.00");
// increase Font Size in running Total
Font tempFont = this.runningTotal.getFont();
tempFont = new Font(tempFont.getName(), tempFont.getStyle(), 30);
this.runningTotal.setFont(tempFont);
// increase Font Size in orderContents
tempFont = this.orderContents.getFont();
tempFont = new Font(tempFont.getName(), tempFont.getStyle(), 18);
this.orderContents.setFont(tempFont);
// make running order scrollable
JScrollPane orderScroll = new JScrollPane(this.orderContents,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
// set-up right-side GUI: clear/submit, order, price
JPanel posRight = new JPanel(new BorderLayout());
posRight.add(menuModifiers, BorderLayout.NORTH);
posRight.add(orderScroll, BorderLayout.CENTER);
posRight.add(this.runningTotal, BorderLayout.SOUTH);
// load menu from file
this.posLeft = this.controller.loadMenu(menuLocation, this.posLeft);
// assemble GUI and frame
this.mainPane.add(this.posLeft);
this.mainPane.add(posRight);
this.mainGUI.setContentPane(mainPane);
this.mainGUI.setSize(1500, 1000);
this.mainGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.mainGUI.setVisible(true);
}
/**
* Getter method for textArea object
*
* @return textArea object
*/
public JTextArea getTextArea() {
return this.orderContents;
}
/**
* Getter method for runningTotal object
*
* @return runningTotal object
*/
public JTextField getRunningTotalArea() {
return this.runningTotal;
}
/**
* Getter method for clear button
*
* @return clearButton
*/
public JButton getClearButton() {
return this.clearOrder;
}
/**
* Getter method for submit button
*
* @return submitButton
*/
public JButton getSubmitButton() {
return this.submitOrder;
}
}