-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubTotalMenu.java
More file actions
143 lines (117 loc) · 4.55 KB
/
SubTotalMenu.java
File metadata and controls
143 lines (117 loc) · 4.55 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
// Jason Jasper
// David Martin-Vaquero
// Jared Mclaren
// Regine Villongco
// Chemen Wong
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
/**
* 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
*
* Sub-Total button will provide the sub-total amount
*/
public class SubTotalMenu extends JFrame
{
private JLabel subTotal = new JLabel();
private double subDouble;
private int orderNumber;
public static DecimalFormat df2 = new DecimalFormat("#0.00");
private JPanel subTotalPanel;
private JButton okButton;
private JPanel actionPanel;
private JLabel message;
/**
Constructor for the sub-total menu.
*/
public SubTotalMenu(int tableNumber)
{
orderNumber = tableNumber;
System.out.println("Order #" + tableNumber + " processing for subtotal");
initComponent();
createElements();
}
/**
Method for creating panes, labels, and buttons for the sub-total menu.
*/
private void createElements(){
JPanel subtotalContainer = new JPanel();
JPanel messageContainer = new JPanel();
SimpleAttributeSet center = new SimpleAttributeSet();
// Set sub-total pane's characteristics.
subtotalContainer.setBorder(BorderFactory.createTitledBorder(null, "Subtotal Amount:",
TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
new Font("Tahoma", Font.PLAIN, 18)));
// Message to the user.
messageContainer.setBorder(BorderFactory.createTitledBorder(null, "To cash out:",
TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
new Font("Tahoma", Font.PLAIN, 18)));
{
// Calculated values.
subDouble = RestaurantPOS.tableArray[orderNumber - 1].getSubAmount(orderNumber);
// Create sub-total label and set its size.
subTotal = new JLabel();
subTotal.setPreferredSize(new Dimension(300, 24));
// Set sub-total label's text characteristics.
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
subTotal.setFont(new Font("Tahoma", Font.PLAIN, 16));
subTotal.setText(df2.format(subDouble));
// Create message label and set its size.
message = new JLabel();
message.setPreferredSize(new Dimension(300, 24));
// Set message label's text characteristics
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
message.setFont(new Font("Tahoma", Font.PLAIN, 12));
message.setText("Click 'Ok' then click 'Cash Out' and then select table #");
// Add labels and buttons to the panes.
subtotalContainer.add(subTotal);
messageContainer.add(message);
}
// Add the panes to the sub-total panel.
subTotalPanel.add(subtotalContainer);
subTotalPanel.add(messageContainer);
}
/**
Method for the ok's button action.
*/
private void cancelButtonActionPerformed(ActionEvent e)
{
this.dispose();
}
/**
Method for creating the sub-total panel and buttons.
*/
private void initComponent()
{
subTotalPanel = new JPanel();
okButton = new JButton();
actionPanel = new JPanel();
//======== set dimensions ========
setTitle("Sub-Total Information");
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
setSize(450, 290);
setLocationRelativeTo(getOwner());
{
actionPanel.setLayout(new GridLayout(1, 3, 10, 0));
// Set cancel button's characteristics.
okButton.setText("Ok");
okButton.setPreferredSize(new Dimension(20, 60));
okButton.setFont(new Font("Tahoma", Font.BOLD, 18));
okButton.addActionListener(e -> cancelButtonActionPerformed(e));
actionPanel.add(okButton);
}
// Set content pane's layout.
contentPane.setLayout(new BorderLayout());
// Add the panels to content pane.
contentPane.add(actionPanel, BorderLayout.PAGE_END);
contentPane.add(subTotalPanel);
}
}