-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentTrackerGUI.java
More file actions
275 lines (223 loc) · 9.92 KB
/
AssignmentTrackerGUI.java
File metadata and controls
275 lines (223 loc) · 9.92 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
package org.app.gui;
import com.formdev.flatlaf.FlatLightLaf;
import org.app.service.*;
import org.app.model.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Main GUI Application for BUP UCAM Assignment Tracker
*/
public class AssignmentTrackerGUI extends JFrame {
private UserService userService;
private CourseService courseService;
private AssignmentService assignmentService;
private User currentUser;
private CardLayout cardLayout;
private JPanel mainPanel;
// Login components
private JTextField emailField;
private JPasswordField passwordField;
private JButton loginButton;
private JButton registerTeacherButton;
private JButton registerStudentButton;
public AssignmentTrackerGUI() {
// Initialize services
userService = new UserService();
courseService = new CourseService();
assignmentService = new AssignmentService();
// Initialize sample data
initializeSampleData();
// Setup GUI
setupLookAndFeel();
initializeComponents();
setupLayout();
setupEventHandlers();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Assignment Tracker");
setSize(1200, 800);
setLocationRelativeTo(null);
setVisible(true);
}
private void setupLookAndFeel() {
try {
FlatLightLaf.setup();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initializeComponents() {
cardLayout = new CardLayout();
mainPanel = new JPanel(cardLayout);
// Create login panel
JPanel loginPanel = createLoginPanel();
mainPanel.add(loginPanel, "LOGIN");
add(mainPanel);
}
private JPanel createLoginPanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(new Color(245, 245, 245));
// Header
JPanel headerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
headerPanel.setBackground(new Color(33, 150, 243));
headerPanel.setPreferredSize(new Dimension(0, 80));
JLabel titleLabel = new JLabel("Assignment Tracker");
titleLabel.setFont(new Font("Arial", Font.BOLD, 28));
titleLabel.setForeground(Color.WHITE);
headerPanel.add(titleLabel);
// Center login form
JPanel centerPanel = new JPanel(new GridBagLayout());
centerPanel.setBackground(new Color(245, 245, 245));
JPanel loginFormPanel = new JPanel(new GridBagLayout());
loginFormPanel.setBackground(Color.WHITE);
loginFormPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createRaisedBevelBorder(),
BorderFactory.createEmptyBorder(30, 40, 30, 40)
));
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);
// Login form title
JLabel formTitle = new JLabel("Login to Your Account");
formTitle.setFont(new Font("Arial", Font.BOLD, 20));
formTitle.setForeground(new Color(33, 150, 243));
gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2;
loginFormPanel.add(formTitle, gbc);
// Email field
gbc.gridwidth = 1;
gbc.gridx = 0; gbc.gridy = 1;
loginFormPanel.add(new JLabel("Email:"), gbc);
emailField = new JTextField(20);
emailField.setFont(new Font("Arial", Font.PLAIN, 14));
gbc.gridx = 1; gbc.gridy = 1;
loginFormPanel.add(emailField, gbc);
// Password field
gbc.gridx = 0; gbc.gridy = 2;
loginFormPanel.add(new JLabel("Password:"), gbc);
passwordField = new JPasswordField(20);
passwordField.setFont(new Font("Arial", Font.PLAIN, 14));
gbc.gridx = 1; gbc.gridy = 2;
loginFormPanel.add(passwordField, gbc);
// Login button
loginButton = new JButton("Login");
loginButton.setFont(new Font("Arial", Font.BOLD, 14));
loginButton.setBackground(new Color(33, 150, 243));
loginButton.setForeground(Color.WHITE);
loginButton.setPreferredSize(new Dimension(100, 35));
gbc.gridx = 0; gbc.gridy = 3; gbc.gridwidth = 2;
loginFormPanel.add(loginButton, gbc);
// Register buttons
JPanel registerPanel = new JPanel(new FlowLayout());
registerPanel.setBackground(Color.WHITE);
registerTeacherButton = new JButton("Register as Teacher");
registerTeacherButton.setFont(new Font("Arial", Font.PLAIN, 12));
registerTeacherButton.setBackground(new Color(76, 175, 80));
registerTeacherButton.setForeground(Color.WHITE);
registerStudentButton = new JButton("Register as Student");
registerStudentButton.setFont(new Font("Arial", Font.PLAIN, 12));
registerStudentButton.setBackground(new Color(255, 152, 0));
registerStudentButton.setForeground(Color.WHITE);
registerPanel.add(registerTeacherButton);
registerPanel.add(registerStudentButton);
gbc.gridx = 0; gbc.gridy = 4; gbc.gridwidth = 2;
loginFormPanel.add(registerPanel, gbc);
centerPanel.add(loginFormPanel);
panel.add(headerPanel, BorderLayout.NORTH);
panel.add(centerPanel, BorderLayout.CENTER);
return panel;
}
private void setupLayout() {
// Layout is already set up in createLoginPanel
}
private void setupEventHandlers() {
loginButton.addActionListener(e -> handleLogin());
registerTeacherButton.addActionListener(e -> showTeacherRegistration());
registerStudentButton.addActionListener(e -> showStudentRegistration());
// Enter key support for login
emailField.addActionListener(e -> passwordField.requestFocus());
passwordField.addActionListener(e -> handleLogin());
}
private void handleLogin() {
String email = emailField.getText().trim();
String password = new String(passwordField.getPassword());
if (email.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(this,
"Please enter both email and password.",
"Login Error",
JOptionPane.WARNING_MESSAGE);
return;
}
currentUser = userService.authenticateUser(email, password);
if (currentUser != null) {
JOptionPane.showMessageDialog(this,
"Welcome, " + currentUser.getName() + "!",
"Login Successful",
JOptionPane.INFORMATION_MESSAGE);
showDashboard();
} else {
JOptionPane.showMessageDialog(this,
"Invalid email or password. Please try again.",
"Login Failed",
JOptionPane.ERROR_MESSAGE);
passwordField.setText("");
}
}
private void showDashboard() {
if (currentUser.getRole() == UserRole.TEACHER) {
TeacherDashboard teacherDashboard = new TeacherDashboard(
(Teacher) currentUser, userService, courseService, assignmentService, this);
mainPanel.add(teacherDashboard, "TEACHER_DASHBOARD");
cardLayout.show(mainPanel, "TEACHER_DASHBOARD");
} else if (currentUser.getRole() == UserRole.STUDENT) {
StudentDashboard studentDashboard = new StudentDashboard(
(Student) currentUser, userService, courseService, assignmentService, this);
mainPanel.add(studentDashboard, "STUDENT_DASHBOARD");
cardLayout.show(mainPanel, "STUDENT_DASHBOARD");
}
}
public void showLogin() {
currentUser = null;
emailField.setText("");
passwordField.setText("");
cardLayout.show(mainPanel, "LOGIN");
}
private void showTeacherRegistration() {
TeacherRegistrationDialog dialog = new TeacherRegistrationDialog(this, userService);
dialog.setVisible(true);
}
private void showStudentRegistration() {
StudentRegistrationDialog dialog = new StudentRegistrationDialog(this, userService);
dialog.setVisible(true);
}
private void initializeSampleData() {
// Only create sample data if this is the first run
if (userService.isFirstRun()) {
System.out.println("First run detected - creating sample data...");
// Create sample teachers
Teacher teacher1 = userService.registerTeacher("Dr. Ahmed Rahman", "ahmed@bup.edu.bd",
"password123", "Computer Science", "EMP001");
Teacher teacher2 = userService.registerTeacher("Prof. Sarah Khan", "sarah@bup.edu.bd",
"password123", "Business Administration", "EMP002");
// Create sample students
Student student1 = userService.registerStudent("Mohammad Ali", "ali@student.bup.edu.bd",
"student123", "201901001", "CSE", 7);
Student student2 = userService.registerStudent("Fatima Hassan", "fatima@student.bup.edu.bd",
"student123", "201901002", "CSE", 7);
// Create sample courses
Course course1 = courseService.createCourse("Object Oriented Programming", "CSE-202",
"Computer Science", 3, "Fall 2024", teacher1);
Course course2 = courseService.createCourse("Business Management", "BBA-101",
"Business Administration", 3, "Fall 2024", teacher2);
// Enroll students in courses
courseService.enrollStudent(course1.getCourseId(), student1);
courseService.enrollStudent(course1.getCourseId(), student2);
courseService.enrollStudent(course2.getCourseId(), student1);
System.out.println("✓ Sample data initialized successfully!");
} else {
System.out.println("✓ Existing data loaded successfully!");
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new AssignmentTrackerGUI());
}
}