-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPurchasePanel.java
177 lines (151 loc) · 4.73 KB
/
PurchasePanel.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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class PurchasePanel extends JPanel {
private JTextField nameTextField;
private JTextField addressTextField;
private JTextField cityTextField;
private JTextField provinceTextField;
private JTextField postalCodeTextField;
private JTextField costTextField;
private JTextField expiryDateTextField;
private JTextField creditCardTextField;
private String creditCardType;
// Make a get method so that the textfields can be accessed externally
public JTextField getNameTextField() { return nameTextField; }
public JTextField getAddressTextField() { return addressTextField; }
public JTextField getCityTextField() { return cityTextField; }
public JTextField getProvinceTextField() { return provinceTextField; }
public JTextField getPostalCodeTextField() { return postalCodeTextField; }
public JTextField getExpiryDateTextField() { return expiryDateTextField; }
public JTextField getCreditCardTextField() { return creditCardTextField; }
public JTextField getCostTextField() { return costTextField; }
public String getCreditCardType() { return creditCardType; }
int cardType;
// Add a constructor that takes the price of the seat(s)
public PurchasePanel (String cost) {
// Make a nice border
setBorder(BorderFactory.createTitledBorder("Customer Information"));
// Create text fields
nameTextField = new JTextField("");
addressTextField = new JTextField("");
cityTextField = new JTextField("");
provinceTextField = new JTextField("");
postalCodeTextField = new JTextField("");
expiryDateTextField = new JTextField("");
creditCardTextField = new JTextField("");
// populate the costTextField with the price of the seat(s)
costTextField = new JTextField(cost);
// Disallow changing of price of the seat(s)
costTextField.setEnabled(false);
// Set the layoutManager and add the components
setLayout(new GridLayout(13,2,5,5));
JLabel aLabel = new JLabel("Name :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(nameTextField);
aLabel = new JLabel("Address :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(addressTextField);
aLabel = new JLabel("City :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(cityTextField);
aLabel = new JLabel("Province :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(provinceTextField);
aLabel = new JLabel("Postal Code :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(postalCodeTextField);
add(new JLabel(""));
add(new JLabel(""));
aLabel = new JLabel("CreditCard :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
ButtonGroup aButtonGroup = new ButtonGroup();
JRadioButton aButton;
aButton = new JRadioButton("MasterCard");
aButtonGroup.add(aButton);
add(aButton);
aButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
creditCardType = e.getActionCommand();
cardType = 0;
}});
add(new JLabel(""));
aButton = new JRadioButton("Visa");
aButtonGroup.add(aButton);
add(aButton);
aButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
creditCardType = e.getActionCommand();
cardType = 1;
}});
add(new JLabel("")); aButton = new JRadioButton("American Express");
aButtonGroup.add(aButton);
add(aButton);
aButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cardType = 2;
creditCardType = e.getActionCommand();
}});
aLabel = new JLabel("Expiry Date :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(expiryDateTextField);
aLabel = new JLabel("Credit Card Number :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(creditCardTextField);
add(new JLabel(""));
add(new JLabel(""));
aLabel = new JLabel("Seat(s) Price :");
aLabel.setHorizontalAlignment(JLabel.RIGHT);
add(aLabel);
add(costTextField);
}
public String getTextName()
{
return(nameTextField.getText());
}
public String getTextAddress()
{
return(addressTextField.getText());
}
public String getTextCity()
{
return(cityTextField.getText());
}
public String getTextProvince()
{
return(provinceTextField.getText());
}
public String getTextPostalCode()
{
return(postalCodeTextField.getText());
}
public String getTextCost()
{
return(costTextField.getText());
}
public String getTextExpiaryDate()
{
return(expiryDateTextField.getText());
}
public String getTextCardNumber()
{
return(creditCardTextField.getText());
}
public String getTextCardType()
{
if (cardType == 0)
return ("MasterCard");
else if (cardType == 1)
return ("Visa");
else
return ("American Express");
}
}