-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProfileSettingPage.java
254 lines (225 loc) · 9.05 KB
/
ProfileSettingPage.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
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
/**
* This class is the graphical implementation of the Profile Settings Page. Customers can edit their profile on this
* page, e.g. update their email and/or address.
*/
public class ProfileSettingPage extends JFrame implements ActionListener
{
// Constants
static final int WIDTH = 1920;
static final int LENGTH = 1080;
// Objects
BankAutomated BA;
HomePage home;
CA customer;
// GUI Components for ProfileSettingPage
private final JButton completeButton;
private final JButton backToHome;
private final JTextField addressField;
private final JTextField phoneNumField;
private final JTextField emailField;
/**
* ProfileSettingPage Constructor, this creates all the frame specifications for this page and graphics positioning
* @param home HomePage object, for the customer to return to when they are done editing their profile
* @param BA BankAutomated object, to process logout if the customer terminated the program
* @param customer CA object, the customer that is currently logged in
*/
public ProfileSettingPage(HomePage home, BankAutomated BA, CA customer)
{
// Set title of the frame
this.setTitle("Profile Settings");
this.setLayout(null);
this.home = home;
this.customer = customer;
this.BA = BA;
// GUI Components
Font labels = new Font("Raleway", Font.BOLD, 30);
Border emptyBorder = BorderFactory.createEmptyBorder();
Border border = BorderFactory.createLineBorder(Color.BLACK, 2);
// GUI Components for email
JLabel email = new JLabel("Update email:");
email.setFont(labels);
email.setBorder(emptyBorder);
email.setForeground(Color.black);
email.setBounds(290,150,300,40);
this.add(email);
// GUI Components for email field
emailField = new JTextField(150);
emailField.setFont(new Font("Arial", Font.PLAIN, 20));
emailField.setBorder(border);
emailField.setBounds(690, 150, 350, 40);
this.add(emailField);
// GUI Components for phone number
JLabel phoneNum = new JLabel("Update phone #:");
phoneNum.setFont(labels);
phoneNum.setBorder(emptyBorder);
phoneNum.setForeground(Color.black);
phoneNum.setBounds(290,275,300,40);
this.add(phoneNum);
// GUI Components for phone number field
phoneNumField = new JTextField(150);
phoneNumField.setFont(new Font("Arial", Font.PLAIN, 20));
phoneNumField.setBorder(border);
phoneNumField.setBounds(690, 275, 350, 40);
this.add(phoneNumField);
// GUI Components for address
JLabel address = new JLabel("Update address:");
address.setFont(labels);
address.setBorder(emptyBorder);
address.setForeground(Color.black);
address.setBounds(290,400,300,40);
this.add(address);
// GUI Components for address field
addressField = new JTextField(150);
addressField.setFont(new Font("Arial", Font.PLAIN, 20));
addressField.setBounds(690, 400, 350, 40);
addressField.setBorder(border);
this.add(addressField);
// GUI Components for complete button
completeButton = new JButton("Complete Transaction");
completeButton.setFont(new Font("SansSerif", Font.PLAIN, 22));
completeButton.setBounds(475, 525, 350, 40);
completeButton.setBackground(Color.black);
completeButton.setForeground(Color.white);
completeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
completeButton.setBorder(emptyBorder);
completeButton.addActionListener(this);
this.add(completeButton);
// GUI Components for back to home button
backToHome = new JButton("Back to Home");
backToHome.setFont(new Font("SansSerif", Font.PLAIN, 22));
backToHome.setBounds(475, 575, 350, 50);
backToHome.setBackground(Color.white);
backToHome.setForeground(new Color(57, 107, 170));
backToHome.setCursor(new Cursor(Cursor.HAND_CURSOR));
backToHome.setContentAreaFilled(false);
backToHome.setFocusPainted(false);
backToHome.setBorder(emptyBorder);
backToHome.setContentAreaFilled(false);
backToHome.addActionListener(this);
this.add(backToHome);
// Window Listener, logout when window is closed
this.addWindowListener(new WindowEventHandler() {
@Override
public void windowClosing(WindowEvent evt) {
//BA.logout (logic.logout) would be called here
//Write all changes to the file
BA.logout();
Window[] windows = Window.getWindows();
for (Window window : windows) {
window.dispose();
}
System.exit(0);
}
});
// Set the background color of the frame
this.getContentPane().setBackground(Color.white);
this.getRootPane().setDefaultButton(completeButton);
this.setSize(WIDTH, LENGTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(false);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
/**
* paint method, overrides the JFrame paint method in order to allow for custom graphical design
* @param g Graphics object
*/
public void paint(Graphics g)
{
super.paint(g);
// Draw the background
Graphics2D g2 = (Graphics2D) g;
Color myRed = new Color(230, 30, 30);
Color myBlack = new Color(160, 32, 32);
GradientPaint redToBlack = new GradientPaint(0, 0, myRed, 0, 150, myBlack);
g2.setPaint(redToBlack);
g2.fillRect(0, 0, WIDTH+1, 150);
// Set font
Font regFont = new Font("Raleway", Font.BOLD, 60);
g2.setFont(regFont);
g2.setColor(new Color(250, 185, 60));
g2.drawString("Edit Profile Settings", 25, 110);
}
/**
* actionPerformed method (implementing ActionListener). When the "Back To Home" button is clicked, it sends
* the customer back to their homepage. When "Save Preferences" is selected, customer changes set are saved
* to their object after being verified by BA.
* @param e ActionEvent object, which listens and keeps track of any button clicks
*/
@Override
public void actionPerformed(ActionEvent e)
{
// back to home button clicked, go back to home page
if (e.getSource() == backToHome)
{
this.setVisible(false);
home.setVisible(true);
}
// complete button clicked, update profile settings
else if (e.getSource() == completeButton)
{
// Get the new information
String email = emailField.getText();
String phoneNum = phoneNumField.getText();
String address = addressField.getText();
// Check if any changes were made
if (email.equals("") && phoneNum.equals("") && address.equals(""))
{
JOptionPane.showMessageDialog(this, "No changes were made.");
return;
}
// Check if the new email is valid
if (!email.equals(""))
{
// Check if the email is valid
if (!BA.validEmail(email))
{
JOptionPane.showMessageDialog(this,"New email is invalid.");
emailField.setText("");
return;
}
// Check if the email is already registered
else if (BA.existingEmail(email))
{
JOptionPane.showMessageDialog(this, "Email is already registered with BCS.");
emailField.setText("");
return;
}
// Email is valid
else
{
customer.setEmail(email);
}
}
// Check if the new phone number is valid
if (!phoneNum.equals(""))
{
// Check if the phone number is valid
if (phoneNum.length() != 10 || !BA.onlyNumeric(phoneNum))
{
JOptionPane.showMessageDialog(this, "Phone number is invalid.");
phoneNumField.setText("");
return;
}
// set the new phone number
else
{
customer.setPhoneNum(phoneNum);
}
}
// Set the new address
if (!address.equals(""))
{
customer.setAddress(address);
}
JOptionPane.showMessageDialog(this, "Your account has been updated.");
this.setVisible(false);
home.setVisible(true);
}
}
}