-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnrollmentFormUI.java
More file actions
287 lines (237 loc) · 10.7 KB
/
Copy pathEnrollmentFormUI.java
File metadata and controls
287 lines (237 loc) · 10.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.HashMap;
public class EnrollmentFormUI {
private static final Color PRIMARY_COLOR = new Color(0, 102, 204);
private static final Font TITLE_FONT = new Font("Segoe UI", Font.BOLD, 28);
private static final Font SUBTITLE_FONT = new Font("Segoe UI", Font.PLAIN, 14);
private static final Font LABEL_FONT = new Font("Segoe UI", Font.BOLD, 12);
private static final Font BUTTON_FONT = new Font("Segoe UI", Font.BOLD, 14);
private static HashMap<String, Student> studentDatabase = new HashMap<>();
// Field declarations
private JTextField idNumberField;
private JTextField firstNameField;
private JTextField lastNameField;
private JTextField emailField;
private JComboBox<String> yearLevelCombo;
private JTextField usernameField;
private JPasswordField passwordField;
private JFrame frame;
public static void openEnrollmentForm() {
new EnrollmentFormUI().initializeForm();
}
private void initializeForm() {
frame = new JFrame("University of Cebu - Enrollment");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setMinimumSize(new Dimension(900, 600));
frame.setLayout(new BorderLayout());
// Initialize all components
initializeComponents();
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void initializeComponents() {
// Main panel with BorderLayout
JPanel mainPanel = new JPanel(new BorderLayout());
frame.add(mainPanel);
// Left panel with university logo and details
JPanel leftPanel = createLeftPanel();
mainPanel.add(leftPanel, BorderLayout.WEST);
// Right panel with enrollment form
JPanel rightPanel = createRightPanel();
mainPanel.add(rightPanel, BorderLayout.CENTER);
}
private JPanel createLeftPanel() {
JPanel leftPanel = new JPanel(new GridBagLayout());
leftPanel.setBackground(PRIMARY_COLOR);
leftPanel.setPreferredSize(new Dimension(400, 600));
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 0, 10, 0);
gbc.anchor = GridBagConstraints.CENTER;
JLabel universityLabel = new JLabel("UNIVERSITY OF CEBU", JLabel.CENTER);
universityLabel.setFont(TITLE_FONT);
universityLabel.setForeground(Color.WHITE);
gbc.gridy = 0;
leftPanel.add(universityLabel, gbc);
JLabel mottoLabel = new JLabel("Excellence • Integrity • Service", JLabel.CENTER);
mottoLabel.setFont(new Font("Segoe UI", Font.ITALIC, 16));
mottoLabel.setForeground(new Color(200, 220, 255));
gbc.gridy = 1;
leftPanel.add(mottoLabel, gbc);
return leftPanel;
}
private JPanel createRightPanel() {
JPanel rightPanel = new JPanel(new GridBagLayout());
rightPanel.setBackground(Color.WHITE);
rightPanel.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
GridBagConstraints gbcRight = new GridBagConstraints();
gbcRight.gridwidth = GridBagConstraints.REMAINDER;
gbcRight.fill = GridBagConstraints.HORIZONTAL;
gbcRight.insets = new Insets(10, 0, 20, 0);
JLabel enrollTitle = new JLabel("Student Enrollment", JLabel.CENTER);
enrollTitle.setFont(TITLE_FONT);
rightPanel.add(enrollTitle, gbcRight);
JLabel subTitle = new JLabel("Please fill in the enrollment form", JLabel.CENTER);
subTitle.setFont(SUBTITLE_FONT);
subTitle.setForeground(Color.GRAY);
rightPanel.add(subTitle, gbcRight);
// Form fields panel
JPanel formFieldsPanel = createFormFieldsPanel();
rightPanel.add(formFieldsPanel, gbcRight);
// Submit button
JButton submitButton = createSubmitButton();
rightPanel.add(submitButton, gbcRight);
// Login link
JPanel loginPanel = createLoginPanel();
rightPanel.add(loginPanel, gbcRight);
return rightPanel;
}
private JPanel createFormFieldsPanel() {
JPanel formFieldsPanel = new JPanel(new GridBagLayout());
formFieldsPanel.setBackground(Color.WHITE);
GridBagConstraints gbcFields = new GridBagConstraints();
gbcFields.insets = new Insets(5, 0, 5, 10);
gbcFields.anchor = GridBagConstraints.WEST;
gbcFields.fill = GridBagConstraints.HORIZONTAL;
// Initialize all fields
idNumberField = new JTextField(20);
firstNameField = new JTextField(20);
lastNameField = new JTextField(20);
emailField = new JTextField(20);
yearLevelCombo = new JComboBox<>(new String[]{"1st Year", "2nd Year", "3rd Year", "4th Year"});
usernameField = new JTextField(20);
passwordField = new JPasswordField(20);
// Style all fields
styleTextField(idNumberField);
styleTextField(firstNameField);
styleTextField(lastNameField);
styleTextField(emailField);
styleTextField(usernameField);
styleTextField(passwordField);
styleComboBox(yearLevelCombo);
// Add fields to form
addFormField(formFieldsPanel, gbcFields, "ID Number:", idNumberField, 0);
addFormField(formFieldsPanel, gbcFields, "First Name:", firstNameField, 1);
addFormField(formFieldsPanel, gbcFields, "Last Name:", lastNameField, 2);
addFormField(formFieldsPanel, gbcFields, "Email:", emailField, 3);
addFormField(formFieldsPanel, gbcFields, "Year Level:", yearLevelCombo, 4);
addFormField(formFieldsPanel, gbcFields, "Username:", usernameField, 5);
addFormField(formFieldsPanel, gbcFields, "Password:", passwordField, 6);
return formFieldsPanel;
}
private void addFormField(JPanel panel, GridBagConstraints gbc, String label, JComponent field, int row) {
gbc.gridx = 0;
gbc.gridy = row;
JLabel jLabel = new JLabel(label);
jLabel.setFont(LABEL_FONT);
panel.add(jLabel, gbc);
gbc.gridx = 1;
panel.add(field, gbc);
}
private JButton createSubmitButton() {
JButton submitButton = new JButton("SUBMIT ENROLLMENT");
submitButton.setFont(BUTTON_FONT);
submitButton.setBackground(PRIMARY_COLOR);
submitButton.setForeground(Color.WHITE);
submitButton.setPreferredSize(new Dimension(0, 45));
submitButton.setFocusPainted(false);
submitButton.addActionListener(e -> submitEnrollment());
return submitButton;
}
private void submitEnrollment() {
String idNumber = idNumberField.getText().trim();
String firstName = firstNameField.getText().trim();
String lastName = lastNameField.getText().trim();
String email = emailField.getText().trim();
String yearLevel = (String) yearLevelCombo.getSelectedItem();
String username = usernameField.getText().trim();
String password = new String(passwordField.getPassword()).trim();
// Validate all fields
if (idNumber.isEmpty() || firstName.isEmpty() || lastName.isEmpty() ||
email.isEmpty() || username.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(frame,
"Please fill all required fields!",
"Error",
JOptionPane.ERROR_MESSAGE);
return;
}
// Create and store new student
Student newStudent = new Student(idNumber, firstName, lastName,
email, yearLevel, username, password);
studentDatabase.put(username, newStudent);
LoginUI.addAccount(username, password, "Student");
// Show success message
JOptionPane.showMessageDialog(frame,
"Enrollment successful!\n" +
"ID: " + idNumber + "\n" +
"Username: " + username,
"Success",
JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
LoginUI.createLoginUI();
}
private JPanel createLoginPanel() {
JPanel loginPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
loginPanel.setBackground(Color.WHITE);
JLabel loginText = new JLabel("Already have an account?");
loginText.setFont(new Font("Segoe UI", Font.PLAIN, 12));
loginPanel.add(loginText);
JLabel loginLink = new JLabel("Login");
loginLink.setFont(new Font("Segoe UI", Font.BOLD, 12));
loginLink.setForeground(PRIMARY_COLOR);
loginLink.setCursor(new Cursor(Cursor.HAND_CURSOR));
loginPanel.add(loginLink);
loginLink.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// Ensure default accounts exist
LoginUI.resetDefaultAccounts();
frame.dispose();
LoginUI.createLoginUI();
}
});
return loginPanel;
}
private static void styleTextField(JComponent field) {
field.setFont(SUBTITLE_FONT);
field.setPreferredSize(new Dimension(200, 30));
field.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(200, 200, 200)),
BorderFactory.createEmptyBorder(5, 10, 5, 10)));
}
private static void styleComboBox(JComboBox<?> comboBox) {
comboBox.setFont(SUBTITLE_FONT);
comboBox.setPreferredSize(new Dimension(200, 30));
comboBox.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(200, 200, 200)),
BorderFactory.createEmptyBorder(5, 10, 5, 10)));
}
public static HashMap<String, Student> getStudentDatabase() {
return studentDatabase;
}
static class Student {
private final String idNumber;
private final String firstName;
private final String lastName;
private final String email;
private final String yearLevel;
private final String username;
private final String password;
public Student(String idNumber, String firstName, String lastName,
String email, String yearLevel, String username, String password) {
this.idNumber = idNumber;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.yearLevel = yearLevel;
this.username = username;
this.password = password;
}
public String getFullName() { return firstName + " " + lastName; }
public String getEmail() { return email; }
public String getYearLevel() { return yearLevel; }
public String getUsername() { return username; }
public String getIdNumber() { return idNumber; }
}
}