-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBakerySystemGUI.java
More file actions
415 lines (355 loc) · 18.7 KB
/
Copy pathBakerySystemGUI.java
File metadata and controls
415 lines (355 loc) · 18.7 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
import javax.swing.*;
public class BakerySystemGUI {
public static void main(String[] args) {
Login login = new Login();
Registration registration = new Registration();
ForgetPassword forgetPassword = new ForgetPassword();
JFrame loginFrame = new JFrame("Wee Ken Shin Bakers - Login");
loginFrame.setSize(1370, 780);
loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loginFrame.setLayout(null);
// System Title
JLabel systemTitle = new JLabel("Welcome to Wee Ken Shin Bakers!");
systemTitle.setBounds(550, 100, 400, 40);
systemTitle.setFont(systemTitle.getFont().deriveFont(20f)); // Larger Font
loginFrame.add(systemTitle);
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(500, 200, 100, 30);
JTextField emailField = new JTextField();
emailField.setBounds(600, 200, 250, 30);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(500, 250, 100, 30);
JPasswordField passwordField = new JPasswordField();
passwordField.setBounds(600, 250, 250, 30);
JButton loginButton = new JButton("Login");
loginButton.setBounds(630, 300, 120, 30);
loginButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/login.png")));
JButton registerButton = new JButton("Register");
registerButton.setBounds(780, 300, 120, 30);
registerButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/new product.png")));
JLabel messageLabel = new JLabel("");
messageLabel.setBounds(500, 350, 400, 30);
JButton forgetPasswordButton = new JButton("Forget Password?");
forgetPasswordButton.setBounds(400, 300, 175, 30);
forgetPasswordButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/change Security Question.png")));
// Adding components to the frame
loginFrame.add(emailLabel);
loginFrame.add(emailField);
loginFrame.add(passwordLabel);
loginFrame.add(passwordField);
loginFrame.add(loginButton);
loginFrame.add(registerButton);
loginFrame.add(messageLabel);
loginFrame.add(systemTitle);
loginFrame.add(forgetPasswordButton);
// Background Image
JLabel bakerybackground = new JLabel();
bakerybackground.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/bakery.jpg")));
bakerybackground.setBounds(0, 0, 1370, 780);
loginFrame.add(bakerybackground);
// Set the background label behind other components
loginFrame.getContentPane().setComponentZOrder(bakerybackground, loginFrame.getContentPane().getComponentCount() - 1);
loginFrame.setVisible(true);
// Login Button Action
loginButton.addActionListener(e -> {
String email = emailField.getText();
String password = new String(passwordField.getPassword());
String role = login.authenticateUser(email, password);
if (role != null) {
messageLabel.setText("Login successful! Role: " + role);
switch (role) {
case "Customer":
int customerId = login.getUserIdByEmail(email);
if (customerId != -1) {
loginFrame.dispose(); // Close login frame
new CustomerOrderPage(customerId); // Open Customer Order Page
} else {
JOptionPane.showMessageDialog(loginFrame, "Error retrieving user ID.");
}
break;
case "Cashier":
loginFrame.dispose(); // Close login frame
new CashierDashboard(); // Open Cashier Dashboard
break;
case "Manager":
loginFrame.dispose(); // Close login frame
int managerId = login.getUserIdByEmail(email); // Get manager's ID based on email (assuming manager is a user)
new ManagerDashboard(managerId); // Pass the managerId to ManagerDashboard constructor
break;
case "Baker":
loginFrame.dispose(); // Close login frame
new BakerDashboard(); // Open Baker Dashboard
break;
default:
JOptionPane.showMessageDialog(loginFrame, "Invalid Role or Incorrect Credentials.");
break;
}
} else {
messageLabel.setText("Invalid email or password. Try again.");
}
});
// Register Button Action
registerButton.addActionListener(e -> {
loginFrame.dispose();
openRegistrationWindow(registration, loginFrame);
});
// Forget Password Button Action
forgetPasswordButton.addActionListener(e -> {
loginFrame.dispose();
openForgetPasswordWindow(forgetPassword, loginFrame);
});
}
// Open Registration Window
public static void openRegistrationWindow(Registration registration, JFrame loginFrame) {
JFrame registerFrame = new JFrame("Wee Ken Shin Bakers - Register");
registerFrame.setSize(1370, 780);
registerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
registerFrame.setLayout(null);
JLabel systemTitle = new JLabel("Wee Ken Shin Bakers - Registration");
systemTitle.setBounds(550, 100, 400, 40);
systemTitle.setFont(systemTitle.getFont().deriveFont(20f)); // Larger Font
registerFrame.add(systemTitle);
JLabel firstNameLabel = new JLabel("First Name:");
firstNameLabel.setBounds(500, 150, 100, 30);
JTextField firstNameField = new JTextField();
firstNameField.setBounds(600, 150, 250, 30);
JLabel lastNameLabel = new JLabel("Last Name:");
lastNameLabel.setBounds(500, 200, 100, 30);
JTextField lastNameField = new JTextField();
lastNameField.setBounds(600, 200, 250, 30);
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(500, 250, 100, 30);
JTextField emailField = new JTextField();
emailField.setBounds(600, 250, 250, 30);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(500, 300, 100, 30);
JPasswordField passwordField = new JPasswordField();
passwordField.setBounds(600, 300, 250, 30);
JLabel confirmPasswordLabel = new JLabel("Confirm Password:");
confirmPasswordLabel.setBounds(500, 350, 150, 30);
JPasswordField confirmPasswordField = new JPasswordField();
confirmPasswordField.setBounds(600, 350, 250, 30);
JLabel securityQuestionLabel = new JLabel("Security Question:");
securityQuestionLabel.setBounds(500, 400, 150, 30);
JTextField securityQuestionField = new JTextField();
securityQuestionField.setBounds(600, 400, 250, 30);
JLabel securityAnswerLabel = new JLabel("Security Answer:");
securityAnswerLabel.setBounds(500, 450, 150, 30);
JTextField securityAnswerField = new JTextField();
securityAnswerField.setBounds(600, 450, 250, 30);
JButton submitButton = new JButton("Submit");
submitButton.setBounds(600, 550, 100, 30);
JLabel messageLabel = new JLabel("");
messageLabel.setBounds(500, 600, 400, 30);
JButton exitButton = new JButton("Exit");
exitButton.setBounds(750, 550, 100, 30);
exitButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/exit small.png")));
registerFrame.add(firstNameLabel);
registerFrame.add(firstNameField);
registerFrame.add(lastNameLabel);
registerFrame.add(lastNameField);
registerFrame.add(emailLabel);
registerFrame.add(emailField);
registerFrame.add(passwordLabel);
registerFrame.add(passwordField);
registerFrame.add(confirmPasswordLabel);
registerFrame.add(confirmPasswordField);
registerFrame.add(securityQuestionLabel);
registerFrame.add(securityQuestionField);
registerFrame.add(securityAnswerLabel);
registerFrame.add(securityAnswerField);
registerFrame.add(submitButton);
registerFrame.add(exitButton);
registerFrame.add(messageLabel);
registerFrame.add(systemTitle);
// Background Image
JLabel bakerybackground = new JLabel();
bakerybackground.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/bakery.jpg")));
bakerybackground.setBounds(0, 0, 1370, 780);
registerFrame.add(bakerybackground);
registerFrame.setVisible(true);
submitButton.addActionListener(e -> {
String firstName = firstNameField.getText();
String lastName = lastNameField.getText();
String email = emailField.getText();
String password = new String(passwordField.getPassword());
String confirmPassword = new String(confirmPasswordField.getPassword());
String securityQuestion = securityQuestionField.getText();
String securityAnswer = securityAnswerField.getText();
PopupWindow popupWindow = new PopupWindow("Are you sure your information is correct?", "Registering.","No changes have been made.");
popupWindow.confirm();
if (popupWindow.confirm()==true)
{
String success = registration.registerUser(firstName, lastName, email, password, confirmPassword, securityQuestion, securityAnswer);
if (null != success)
switch (success) {
case "Same":
messageLabel.setText("Passwords do not match.");
break;
case "Success":
messageLabel.setText("Registration successful!");
break;
case "Fail":
messageLabel.setText("Registration failed. Try again.");
break;
default:
break;
}
}
});
// Exit Button Action
exitButton.addActionListener(e -> {
registerFrame.dispose(); // Close the registration window
loginFrame.setVisible(true); // Show the login window again
});
}
// Forget Password Window
public static void openForgetPasswordWindow(ForgetPassword forgetPassword, JFrame loginFrame) {
JFrame forgetFrame = new JFrame("Wee Ken Shin Bakers - Forget Password");
forgetFrame.setSize(1370, 780);
forgetFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
forgetFrame.setLayout(null);
// System Title
JLabel systemTitle = new JLabel("Wee Ken Shin Bakers - Forget Password");
systemTitle.setBounds(550, 100, 400, 40);
systemTitle.setFont(systemTitle.getFont().deriveFont(20f)); // Larger Font
forgetFrame.add(systemTitle);
// Components setup
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(500, 150, 100, 30);
JTextField emailField = new JTextField();
emailField.setBounds(600, 150, 250, 30);
JButton checkButton = new JButton("Check");
checkButton.setBounds(900, 150, 100, 30);
checkButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/search.png")));
JLabel messageLabel = new JLabel("");
messageLabel.setBounds(500, 200, 400, 30);
// Security Question Fields
JLabel securityAnswerLabel = new JLabel("Security Answer:");
securityAnswerLabel.setBounds(500, 250, 150, 30);
JTextField securityAnswerField = new JTextField();
securityAnswerField.setBounds(600, 250, 250, 30);
JButton verifyButton = new JButton("Verify");
verifyButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/verify users.png")));
verifyButton.setBounds(900, 250, 100, 30);
JLabel messageLabel2 = new JLabel("");
messageLabel2.setBounds(500, 300, 400, 30);
// New Password Fields
JLabel newPasswordLabel = new JLabel("New Password:");
newPasswordLabel.setBounds(500, 350, 150, 30);
JTextField newPasswordField = new JTextField();
newPasswordField.setBounds(600, 350, 250, 30);
JLabel confirmPasswordLabel = new JLabel("Confirm Password:");
confirmPasswordLabel.setBounds(480, 400, 150, 30);
JTextField confirmPasswordField = new JTextField();
confirmPasswordField.setBounds(600, 400, 250, 30);
JButton changePasswordButton = new JButton("Change Password");
changePasswordButton.setBounds(900, 400, 200, 30);
changePasswordButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/change Password.png")));
JLabel messageLabel3 = new JLabel("");
messageLabel3.setBounds(500, 450, 400, 30);
// Exit Button
JButton exitButton = new JButton("Exit");
exitButton.setBounds(750, 550, 100, 30);
exitButton.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/exit small.png")));
// Add components
forgetFrame.add(emailLabel);
forgetFrame.add(emailField);
forgetFrame.add(checkButton);
forgetFrame.add(messageLabel);
forgetFrame.add(securityAnswerLabel);
forgetFrame.add(securityAnswerField);
forgetFrame.add(verifyButton);
forgetFrame.add(messageLabel2);
forgetFrame.add(newPasswordLabel);
forgetFrame.add(newPasswordField);
forgetFrame.add(confirmPasswordLabel);
forgetFrame.add(confirmPasswordField);
forgetFrame.add(changePasswordButton);
forgetFrame.add(messageLabel3);
forgetFrame.add(exitButton);
// Background Image
JLabel bakerybackground = new JLabel();
bakerybackground.setIcon(new javax.swing.ImageIcon(BakerySystemGUI.class.getResource("/images/bakery.jpg")));
bakerybackground.setBounds(0, 0, 1370, 780);
forgetFrame.add(bakerybackground);
forgetFrame.setVisible(true);
// Initially hide components
securityAnswerField.setVisible(false);
securityAnswerLabel.setVisible(false);
verifyButton.setVisible(false);
newPasswordLabel.setVisible(false);
newPasswordField.setVisible(false);
confirmPasswordLabel.setVisible(false);
confirmPasswordField.setVisible(false);
changePasswordButton.setVisible(false);
// Check Button Action
checkButton.addActionListener(e -> {
String email = emailField.getText();
String securityQuestion = forgetPassword.getSecurityQuestion(email);
if (securityQuestion != null) {
messageLabel.setText("Email Found! Security Question: " + securityQuestion);
securityAnswerField.setVisible(true);
securityAnswerLabel.setVisible(true);
verifyButton.setVisible(true);
messageLabel2.setVisible(true);
} else {
messageLabel.setText("Email not found. Try again.");
securityAnswerField.setVisible(false);
securityAnswerLabel.setVisible(false);
verifyButton.setVisible(false);
messageLabel2.setVisible(false);
newPasswordLabel.setVisible(false);
newPasswordField.setVisible(false);
confirmPasswordLabel.setVisible(false);
confirmPasswordField.setVisible(false);
changePasswordButton.setVisible(false);
}
});
// Verify Button Action
verifyButton.addActionListener(e -> {
String email = emailField.getText();
String securityAnswer = securityAnswerField.getText();
boolean verify = forgetPassword.verifySecurityAnswer(email, securityAnswer);
if (verify) {
messageLabel2.setText("Email Verified!!");
newPasswordLabel.setVisible(true);
newPasswordField.setVisible(true);
confirmPasswordLabel.setVisible(true);
confirmPasswordField.setVisible(true);
changePasswordButton.setVisible(true);
} else {
messageLabel2.setText("Security Answer Incorrect. Try again.");
newPasswordLabel.setVisible(false);
newPasswordField.setVisible(false);
confirmPasswordLabel.setVisible(false);
confirmPasswordField.setVisible(false);
changePasswordButton.setVisible(false);
}
});
// Change Password Button Action
changePasswordButton.addActionListener(e -> {
String email = emailField.getText();
String securityAnswer = securityAnswerField.getText();
String newPassword = newPasswordField.getText();
String confirmPassword = confirmPasswordField.getText();
String changePassword = forgetPassword.changePassword(email, securityAnswer, newPassword, confirmPassword);
PopupWindow popupWindow = new PopupWindow("Are you sure you want to change password?", "Changing Password.","No changes have been made.");
popupWindow.confirm();
if(popupWindow.confirm()== true){
if ("donotmatch".equals(changePassword)) {
messageLabel3.setText("Password Do Not Match");
} else if ("same".equals(changePassword)) {
messageLabel3.setText("New Password is Old Password");
} else {
messageLabel3.setText("Password Changed!!");
}
}
});
// Exit Button Action
exitButton.addActionListener(e -> {
forgetFrame.dispose(); // Close the forget password window
loginFrame.setVisible(true); // Show the login window again
});
}
}