Java Project
Java Project
Introduction
Class Diagram
154
Codes
Login. Java
package attendance;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
/**
* [Link] – Insert / Update / Delete / View classes.
*/
public class ClassForm extends JPanel {
public ClassForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
buildUI();
loadSubjects();
loadTable();
}
155
[Link](false);
[Link](new Color(240, 240, 240));
156
[Link](e -> { loadSubjects(); loadTable();
});
}
157
[Link](this, "Class updated!",
"Success", JOptionPane.INFORMATION_MESSAGE);
clearForm(); loadTable();
} catch (SQLException ex) { showError(ex); }
}
158
[Link]([Link](row, 2).toString());
[Link]([Link](row, 3).toString());
}
159
[Link](new Font("Segoe UI", [Link], 13));
[Link](28);
[Link]().setFont(new Font("Segoe UI", [Link], 13));
[Link]().setBackground(new Color(74, 20, 140));
[Link]().setForeground([Link]);
[Link](new Color(225, 190, 231));
[Link](new Color(220, 220, 230));
}
private void showError(SQLException ex) {
[Link](this, "Error: " + [Link](),
"DB Error", JOptionPane.ERROR_MESSAGE);
}
private void warn(String msg) {
[Link](this, msg, "Warning",
JOptionPane.WARNING_MESSAGE);
}
}
[Link]
package attendance;
import [Link];
import [Link];
import [Link];
private DBConnection() {}
160
[Link]("Connection failed: " + [Link]());
}
return connection;
}
}
[Link]
package attendance;
import [Link].*;
import [Link].*;
import [Link].*;
// Top bar
JPanel topBar = new JPanel(new BorderLayout());
[Link](new Color(26, 35, 126));
[Link](new Dimension(1100, 55));
[Link]([Link](0, 20, 0, 20));
JLabel title = new JLabel(" Attendance Management System");
[Link](new Font("Segoe UI", [Link], 18));
[Link]([Link]);
[Link](title, [Link]);
JLabel userLbl = new JLabel("User: " + currentUser + " | " +
[Link]() + " ");
[Link](new Font("Segoe UI", [Link], 13));
[Link](new Color(200, 220, 255));
[Link](userLbl, [Link]);
[Link](topBar, [Link]);
// Sidebar
161
JPanel sidebar = new JPanel();
[Link](new BoxLayout(sidebar, BoxLayout.Y_AXIS));
[Link](new Color(21, 27, 85));
[Link](new Dimension(220, 700));
[Link]([Link](15, 0, 10, 0));
String[] menus = {
" Home",
" Student Management",
" Subject Management",
" Class Management",
" Attendance Marking",
" Attendance Summary",
" Logout"
};
for (String m : menus) {
JButton btn = new JButton(m);
[Link](new Font("Segoe UI", [Link], 14));
[Link](new Color(210, 220, 255));
[Link](new Color(21, 27, 85));
[Link](false);
[Link](false);
[Link](new Dimension(220, 46));
[Link](new Dimension(220, 46));
[Link]([Link]);
[Link]([Link](0, 20, 0, 0));
[Link](new Cursor(Cursor.HAND_CURSOR));
[Link](new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
[Link](new Color(40, 53, 147)); }
public void mouseExited(MouseEvent e) {
[Link](new Color(21, 27, 85)); }
});
[Link](e -> navigate([Link]()));
[Link](btn);
[Link]([Link](new Dimension(0, 3)));
}
[Link](sidebar, [Link]);
// Content
contentPanel = new JPanel(new BorderLayout());
[Link](new Color(245, 247, 250));
showHome();
[Link](contentPanel, [Link]);
}
162
else if ([Link]("Student")) [Link](new
StudentForm(), [Link]);
else if ([Link]("Subject")) [Link](new
SubjectForm(), [Link]);
else if ([Link]("Class")) [Link](new
ClassForm(), [Link]);
else if ([Link]("Marking")) [Link](new
AttendanceForm(), [Link]);
else if ([Link]("Summary")) [Link](new
SummaryForm(), [Link]);
else if ([Link]("Logout")) {
int c = [Link](this, "Logout?",
"Confirm", JOptionPane.YES_NO_OPTION);
if (c == JOptionPane.YES_OPTION) { new Login(); dispose();
return; }
}
[Link]();
[Link]();
}
// Cards
String[] icons = {" ", "📘", "📝", "📊"};
String[] titles = {"Students", "Subjects", "Attendance",
"Summary"};
Color[] colors = {new Color(63,81,181), new Color(0,150,136), new
Color(244,67,54), new Color(255,152,0)};
163
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Link](colors[idx]);
[Link](0, 0, getWidth(), getHeight(), 16,
16);
}
};
[Link](false);
[Link](40 + i * 185, 140, 165, 150);
[Link](card);
}
[Link](home, [Link]);
}
}
[Link]
package attendance;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public StudentForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
buildUI();
loadTable();
}
164
private void buildUI() {
// Header
JPanel header = new JPanel(new BorderLayout());
[Link](new Color(26, 35, 126));
[Link](new Dimension(0, 50));
JLabel lbl = new JLabel(" Student Management");
[Link](new Font("Segoe UI", [Link], 17));
[Link]([Link]);
[Link](lbl, [Link]);
add(header, [Link]);
// Form Panel
JPanel form = new JPanel(null);
[Link]([Link]);
[Link](new Dimension(0, 240));
// Table
165
tableModel = new DefaultTableModel(new String[]{"ID","Name","Roll
No","Department","Year"}, 0) {
public boolean isCellEditable(int r, int c) { return false; }
};
table = new JTable(tableModel);
[Link](new Font("Segoe UI", [Link], 13));
[Link](28);
[Link]().setFont(new Font("Segoe UI", [Link],
13));
[Link]().setBackground(new Color(26,35,126));
[Link]().setForeground([Link]);
[Link](new Color(197,202,233));
[Link](new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int row = [Link]();
if (row >= 0) {
[Link]([Link](row,
0).toString());
[Link]([Link](row,
1).toString());
[Link]([Link](row,
2).toString());
[Link]([Link](row,
3).toString());
[Link]([Link](row,
4).toString());
}
}
});
add(new JScrollPane(table), [Link]);
// Button actions
[Link](e -> {
if ([Link]().isEmpty() || [Link]().isEmpty()
|| [Link]().isEmpty()) {
[Link](this, "Fill all fields!");
return;
}
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"INSERT INTO STUDENTS
(student_name,roll_no,department,year) VALUES(?,?,?,?)")) {
[Link](1, [Link]().trim());
[Link](2, [Link]().trim());
[Link](3, [Link]().trim());
[Link](4,
[Link]((String)[Link]()));
[Link]();
[Link](this, "Student added
successfully!");
166
clearFields(); loadTable();
} catch (SQLException ex) {
[Link](this, "Error: " +
[Link]());
}
});
[Link](e -> {
if ([Link]().isEmpty()) {
[Link](this, "Select a row first!"); return; }
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"UPDATE STUDENTS SET
student_name=?,roll_no=?,department=?,year=? WHERE student_id=?")) {
[Link](1, [Link]().trim());
[Link](2, [Link]().trim());
[Link](3, [Link]().trim());
[Link](4,
[Link]((String)[Link]()));
[Link](5, [Link]([Link]().trim()));
[Link]();
[Link](this, "Student updated
successfully!");
clearFields(); loadTable();
} catch (SQLException ex) {
[Link](this, "Error: " +
[Link]());
}
});
[Link](e -> {
if ([Link]().isEmpty()) {
[Link](this, "Select a row first!"); return; }
int confirm = [Link](this, "Delete this
student?");
if (confirm != JOptionPane.YES_OPTION) return;
try (Connection c = [Link]();
PreparedStatement ps = [Link]("DELETE FROM
STUDENTS WHERE student_id=?")) {
[Link](1, [Link]([Link]().trim()));
[Link]();
[Link](this, "Student deleted!");
clearFields(); loadTable();
} catch (SQLException ex) {
[Link](this, "Error: " +
[Link]());
}
});
167
}
168
[Link](new Cursor(Cursor.HAND_CURSOR));
return b;
}
}
Subject [Link]
package attendance;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public SubjectForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
buildUI();
loadTable();
}
169
txtSubName = addField(form, 450, 28, 220, 30);
170
[Link](e -> {
if ([Link]().isEmpty() ||
[Link]().isEmpty()) {
[Link](this, "Fill all fields!");
return;
}
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"INSERT INTO SUBJECTS
(subject_name,faculty_name,semester) VALUES(?,?,?)")) {
[Link](1, [Link]().trim());
[Link](2, [Link]().trim());
[Link](3,
[Link]((String)[Link]()));
[Link]();
[Link](this, "Subject added!");
clearFields(); loadTable();
} catch (SQLException ex) { [Link](this,
"Error: " + [Link]()); }
});
[Link](e -> {
if ([Link]().isEmpty()) {
[Link](this, "Select row first!"); return; }
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"UPDATE SUBJECTS SET
subject_name=?,faculty_name=?,semester=? WHERE subject_id=?")) {
[Link](1, [Link]().trim());
[Link](2, [Link]().trim());
[Link](3,
[Link]((String)[Link]()));
[Link](4, [Link]([Link]().trim()));
[Link]();
[Link](this, "Subject updated!");
clearFields(); loadTable();
} catch (SQLException ex) { [Link](this,
"Error: " + [Link]()); }
});
[Link](e -> {
if ([Link]().isEmpty()) {
[Link](this, "Select row first!"); return; }
if ([Link](this,"Delete?") !=
JOptionPane.YES_OPTION) return;
try (Connection c = [Link]();
PreparedStatement ps = [Link]("DELETE FROM
SUBJECTS WHERE subject_id=?")) {
[Link](1, [Link]([Link]().trim()));
171
[Link]();
[Link](this, "Deleted!");
clearFields(); loadTable();
} catch (SQLException ex) { [Link](this,
"Error: " + [Link]()); }
});
172
}
}
[Link]
package attendance;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
/**
* [Link] – Mark / Update / Delete / View attendance records.
*/
public class AttendanceForm extends JPanel {
public AttendanceForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
buildUI();
populateCombos();
loadTable();
}
173
[Link]([Link](0, 0, 1, 0, new
Color(220, 220, 220)));
// Table
String[] cols = {"ID","Student","Roll
No","Subject","Date","Status"};
tableModel = new DefaultTableModel(cols, 0) {
174
public boolean isCellEditable(int r, int c) { return false; }
};
table = new JTable(tableModel);
styleTable(table);
[Link](new MouseAdapter() {
public void mouseClicked(MouseEvent e) { rowToForm(); }
});
JScrollPane scroll = new JScrollPane(table);
[Link]([Link](10, 15, 15, 15));
add(scroll, [Link]);
175
[Link](); [Link]();
176
private void delete() {
if ([Link]().isEmpty()) { warn("Select a row first.");
return; }
if ([Link](this,"Delete this
record?","Confirm",JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
try (Connection c = [Link]();
PreparedStatement ps = [Link]("DELETE FROM
ATTENDANCE WHERE attendance_id=?")) {
[Link](1, [Link]([Link]().trim()));
[Link]();
[Link](this, "Record deleted!",
"Success", JOptionPane.INFORMATION_MESSAGE);
clearForm(); loadTable();
} catch (SQLException ex) { showError(ex); }
}
177
String subjectName = [Link](row, 3).toString();
for (int i = 0; i < [Link](); i++)
if ([Link](i).toString().contains(studentName)) {
[Link](i); break; }
for (int i = 0; i < [Link](); i++)
if ([Link](i).toString().contains(subjectName)) {
[Link](i); break; }
}
178
private JButton makeBtn(String t, Color bg, int x, int y) {
JButton btn = new JButton(t);
[Link](new Font("Segoe UI", [Link], 12));
[Link](bg); [Link]([Link]);
[Link](false); [Link](false);
[Link](x, y, 115, 34);
[Link](new Cursor(Cursor.HAND_CURSOR));
return btn;
}
private void styleTable(JTable t) {
[Link](new Font("Segoe UI", [Link], 13));
[Link](28);
[Link]().setFont(new Font("Segoe UI", [Link], 13));
[Link]().setBackground(new Color(183, 28, 28));
[Link]().setForeground([Link]);
[Link](new Color(220, 220, 230));
}
private void showError(SQLException ex) {
[Link](this, "Error: " + [Link](),
"DB Error", JOptionPane.ERROR_MESSAGE);
}
private void warn(String msg) {
[Link](this, msg, "Warning",
JOptionPane.WARNING_MESSAGE);
}
}
[Link]
package attendance;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public SubjectForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
179
buildUI();
loadTable();
}
180
tableModel = new DefaultTableModel(new String[]{"ID","Subject
Name","Faculty","Semester"}, 0) {
public boolean isCellEditable(int r, int c) { return
false; }
};
table = new JTable(tableModel);
[Link](new Font("Segoe UI", [Link], 13));
[Link](28);
[Link]().setFont(new Font("Segoe UI",
[Link], 13));
[Link]().setBackground(new Color(0,105,92));
[Link]().setForeground([Link]);
[Link](new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int row = [Link]();
if (row >= 0) {
[Link]([Link](row,
0).toString());
[Link]([Link](row,
1).toString());
[Link]([Link](row,
2).toString());
[Link]([Link](row,
3).toString());
}
}
});
add(new JScrollPane(table), [Link]);
[Link](e -> {
if ([Link]().isEmpty() ||
[Link]().isEmpty()) {
[Link](this, "Fill all
fields!"); return;
}
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"INSERT INTO SUBJECTS
(subject_name,faculty_name,semester) VALUES(?,?,?)")) {
[Link](1, [Link]().trim());
[Link](2, [Link]().trim());
[Link](3,
[Link]((String)[Link]()));
[Link]();
181
[Link](this, "Subject
added!");
clearFields(); loadTable();
} catch (SQLException ex) {
[Link](this, "Error: " + [Link]()); }
});
[Link](e -> {
if ([Link]().isEmpty()) {
[Link](this, "Select row first!"); return; }
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"UPDATE SUBJECTS SET
subject_name=?,faculty_name=?,semester=? WHERE subject_id=?")) {
[Link](1, [Link]().trim());
[Link](2, [Link]().trim());
[Link](3,
[Link]((String)[Link]()));
[Link](4,
[Link]([Link]().trim()));
[Link]();
[Link](this, "Subject
updated!");
clearFields(); loadTable();
} catch (SQLException ex) {
[Link](this, "Error: " + [Link]()); }
});
[Link](e -> {
if ([Link]().isEmpty()) {
[Link](this, "Select row first!"); return; }
if ([Link](this,"Delete?") !=
JOptionPane.YES_OPTION) return;
try (Connection c = [Link]();
PreparedStatement ps = [Link]("DELETE
FROM SUBJECTS WHERE subject_id=?")) {
[Link](1,
[Link]([Link]().trim()));
[Link]();
[Link](this, "Deleted!");
clearFields(); loadTable();
} catch (SQLException ex) {
[Link](this, "Error: " + [Link]()); }
});
182
}
183
}
}
Screenshots
184
185
186
187