0% found this document useful (0 votes)
7 views34 pages

Java Project

The Attendance Management System is a Java-based application designed to streamline student attendance tracking in educational institutions. It replaces manual attendance methods with a digital solution, providing features for managing student records, subject details, and attendance summaries. The system is built using Java Swing and connects to an Oracle Database for backend operations.

Uploaded by

aaradhyamadhav90
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views34 pages

Java Project

The Attendance Management System is a Java-based application designed to streamline student attendance tracking in educational institutions. It replaces manual attendance methods with a digital solution, providing features for managing student records, subject details, and attendance summaries. The system is built using Java Swing and connects to an Oracle Database for backend operations.

Uploaded by

aaradhyamadhav90
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program No: 63 Date: 04/03/2026

Program Title:Project – Attendance Tracker

Introduction

The Attendance Management System is a Java-based desktop application


developed using Java Swing (JFrame) in NetBeans IDE with Oracle
Database 23ai as the backend.

The system is designed to manage student attendance efficiently in


colleges or institutions. It provides a structured way to maintain
student records, subject details, class information, daily attendance
records, and attendance summaries.

This system eliminates manual attendance tracking and ensures


accurate calculation of attendance percentage.

Objective of the Project

The main objective of the Attendance Management System is to develop


a computerized system that helps institutions manage and monitor
student attendance efficiently. The system aims to replace the
traditional manual method of recording attendance with a faster, more
accurate, and organized digital solution.

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 {

private JTextField txtId, txtSection;


private JComboBox<String> cmbYear;
private JComboBox<Object> cmbSubject;
private JButton btnAdd, btnUpdate, btnDelete, btnClear, btnRefresh;
private JTable table;
private DefaultTableModel tableModel;

public ClassForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
buildUI();
loadSubjects();
loadTable();
}

private void buildUI() {


JPanel header = new JPanel(new BorderLayout());
[Link](new Color(74, 20, 140));
[Link](new Dimension(0, 50));
JLabel lbl = new JLabel(" 🏫 Class Management");
[Link](new Font("Segoe UI", [Link], 17));
[Link]([Link]);
[Link](lbl, [Link]);
add(header, [Link]);

JPanel form = new JPanel(null);


[Link]([Link]);
[Link](new Dimension(0, 190));
[Link]([Link](0, 0, 1, 0, new
Color(220, 220, 220)));

addLabel(form, "Class ID (auto):", 30, 30);


txtId = addField(form, 200, 28, 100, 30);

155
[Link](false);
[Link](new Color(240, 240, 240));

addLabel(form, "Subject *:", 360, 30);


cmbSubject = new JComboBox<>();
[Link](460, 28, 280, 30);
[Link](new Font("Segoe UI", [Link], 12));
[Link](cmbSubject);

addLabel(form, "Year *:", 30, 80);


cmbYear = new JComboBox<>(new String[]{"1","2","3","4"});
[Link](200, 78, 80, 30);
[Link](cmbYear);

addLabel(form, "Section *:", 360, 80);


txtSection = addField(form, 460, 78, 80, 30);

btnAdd = makeBtn("➕ Add", new Color(46, 125, 50), 30,


140);
btnUpdate = makeBtn("✏ Update", new Color(21, 101, 192), 145,
140);
btnDelete = makeBtn("🗑 Delete", new Color(183, 28, 28), 260,
140);
btnClear = makeBtn("🔄 Clear", new Color(97, 97, 97), 375,
140);
btnRefresh = makeBtn("🔃 Refresh",new Color(0, 131, 143), 490,
140);
[Link](btnAdd); [Link](btnUpdate);
[Link](btnDelete); [Link](btnClear); [Link](btnRefresh);
add(form, [Link]);

String[] cols = {"Class ID","Subject","Year","Section"};


tableModel = new DefaultTableModel(cols, 0) {
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]);

[Link](e -> insert());


[Link](e -> update());
[Link](e -> delete());
[Link](e -> clearForm());

156
[Link](e -> { loadSubjects(); loadTable();
});
}

private void loadSubjects() {


[Link]();
try (Connection c = [Link]();
PreparedStatement ps = [Link]("SELECT subject_id,
subject_name FROM SUBJECTS ORDER BY subject_id");
ResultSet rs = [Link]()) {
while ([Link]())
[Link]([Link]("subject_id") + " – " +
[Link]("subject_name"));
} catch (SQLException ex) { showError(ex); }
}

private void insert() {


if (!checkFields()) return;
int subId = getSelectedSubjectId();
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"INSERT INTO CLASSES (subject_id,year,section)
VALUES(?,?,?)")) {
[Link](1, subId);
[Link](2, [Link]((String)
[Link]()));
[Link](3, [Link]().trim().toUpperCase());
[Link]();
[Link](this, "Class created!",
"Success", JOptionPane.INFORMATION_MESSAGE);
clearForm(); loadTable();
} catch (SQLException ex) { showError(ex); }
}

private void update() {


if ([Link]().isEmpty()) { warn("Select a row first.");
return; }
if (!checkFields()) return;
int subId = getSelectedSubjectId();
try (Connection c = [Link]();
PreparedStatement ps = [Link](
"UPDATE CLASSES SET subject_id=?,year=?,section=? WHERE
class_id=?")) {
[Link](1, subId);
[Link](2, [Link]((String)
[Link]()));
[Link](3, [Link]().trim().toUpperCase());
[Link](4, [Link]([Link]().trim()));
[Link]();

157
[Link](this, "Class updated!",
"Success", JOptionPane.INFORMATION_MESSAGE);
clearForm(); loadTable();
} catch (SQLException ex) { showError(ex); }
}

private void delete() {


if ([Link]().isEmpty()) { warn("Select a row first.");
return; }
if ([Link](this,"Delete this
class?","Confirm",JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
try (Connection c = [Link]();
PreparedStatement ps = [Link]("DELETE FROM CLASSES
WHERE class_id=?")) {
[Link](1, [Link]([Link]().trim()));
[Link]();
[Link](this, "Class deleted!",
"Success", JOptionPane.INFORMATION_MESSAGE);
clearForm(); loadTable();
} catch (SQLException ex) { showError(ex); }
}

private void loadTable() {


[Link](0);
String sql = "SELECT cl.class_id, s.subject_name, [Link],
[Link] " +
"FROM CLASSES cl JOIN SUBJECTS s ON
cl.subject_id=s.subject_id ORDER BY cl.class_id";
try (Connection c = [Link]();
PreparedStatement ps = [Link](sql);
ResultSet rs = [Link]()) {
while ([Link]())
[Link](new Object[]{
[Link]("class_id"), [Link]("subject_name"),
[Link]("year"), [Link]("section")
});
} catch (SQLException ex) { showError(ex); }
}

private void rowToForm() {


int row = [Link]();
if (row == -1) return;
[Link]([Link](row, 0).toString());
String subName = [Link](row, 1).toString();
for (int i = 0; i < [Link](); i++) {
if ([Link](i).toString().contains(subName)) {
[Link](i); break;
}
}

158
[Link]([Link](row, 2).toString());
[Link]([Link](row, 3).toString());
}

private void clearForm() {


[Link](""); [Link]("");
if ([Link]() > 0) [Link](0);
[Link](0);
}

private int getSelectedSubjectId() {


String sel = [Link]().toString();
return [Link]([Link](" – ")[0].trim());
}

private boolean checkFields() {


if ([Link]() == 0 ||
[Link]().trim().isEmpty()) {
warn("Please fill all required fields (*)."); return false;
}
return true;
}

private void addLabel(JPanel p, String t, int x, int y) {


JLabel l = new JLabel(t);
[Link](new Font("Segoe UI", [Link], 12));
[Link](new Color(60, 60, 70));
[Link](x, y, 160, 20);
[Link](l);
}
private JTextField addField(JPanel p, int x, int y, int w, int h) {
JTextField f = new JTextField();
[Link](new Font("Segoe UI", [Link], 13));
[Link]([Link](
[Link](new Color(180, 180, 200)),
[Link](4, 6, 4, 6)));
[Link](x, y, w, h);
[Link](f);
return f;
}
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, 110, 34);
[Link](new Cursor(Cursor.HAND_CURSOR));
return btn;
}
private void styleTable(JTable t) {

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];

public class DBConnection {

// Change password to YOUR Oracle password


private static final String URL =
"jdbc:oracle:thin:@localhost:1521/XEPDB1";
private static final String USERNAME = "c##aarathi";
private static final String PASSWORD = "user"; // <-- change this if
different

private static Connection connection = null;

private DBConnection() {}

public static Connection getConnection() {


try {
if (connection == null || [Link]()) {
[Link]("[Link]");
connection = [Link](URL, USERNAME,
PASSWORD);
[Link]("Database connected!");
}
} catch (ClassNotFoundException e) {
[Link]("Driver not found: " + [Link]());
} catch (SQLException e) {

160
[Link]("Connection failed: " + [Link]());
}
return connection;
}
}

[Link]
package attendance;

import [Link].*;
import [Link].*;
import [Link].*;

public class Dashboard extends JFrame {

private String currentUser, currentRole;


private JPanel contentPanel;

public Dashboard(String user, String role) {


[Link] = user;
[Link] = role;
initComponents();
setTitle("Dashboard - Attendance Management System");
setSize(1100, 700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}

private void initComponents() {


JPanel root = new JPanel(new BorderLayout());
setContentPane(root);

// 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]);
}

private void navigate(String menu) {


[Link]();
if ([Link]("Home")) showHome();

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]();
}

private void showHome() {


JPanel home = new JPanel(null);
[Link](new Color(245, 247, 250));

JLabel lbl = new JLabel("Welcome to Attendance Management System");


[Link](new Font("Segoe UI", [Link], 22));
[Link](new Color(26, 35, 126));
[Link](40, 40, 600, 35);
[Link](lbl);

JLabel sub = new JLabel("Select a module from the sidebar to get


started.");
[Link](new Font("Segoe UI", [Link], 14));
[Link]([Link]);
[Link](40, 80, 500, 22);
[Link](sub);

// 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)};

for (int i = 0; i < 4; i++) {


final int idx = i;
JPanel card = new JPanel(null) {
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;

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);

JLabel ico = new JLabel(icons[i], [Link]);


[Link](new Font("Segoe UI Emoji", [Link], 32));
[Link](0, 15, 165, 42);
[Link](ico);

JLabel ttl = new JLabel(titles[i], [Link]);


[Link](new Font("Segoe UI", [Link], 15));
[Link]([Link]);
[Link](0, 65, 165, 22);
[Link](ttl);

[Link](card);
}
[Link](home, [Link]);
}
}
[Link]
package attendance;

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class StudentForm extends JPanel {

private JTextField txtId, txtName, txtRoll, txtDept;


private JComboBox<String> cmbYear;
private JTable table;
private DefaultTableModel tableModel;

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));

addLabel(form, "Student ID:", 30, 30);


txtId = addField(form, 180, 28, 100, 30);
[Link](false);
[Link](new Color(230, 230, 230));

addLabel(form, "Student Name *:", 330, 30);


txtName = addField(form, 480, 28, 200, 30);

addLabel(form, "Roll No *:", 30, 80);


txtRoll = addField(form, 180, 78, 120, 30);

addLabel(form, "Department *:", 330, 80);


txtDept = addField(form, 480, 78, 200, 30);

addLabel(form, "Year *:", 30, 130);


cmbYear = new JComboBox<>(new String[]{"1","2","3","4"});
[Link](180, 128, 80, 30);
[Link](cmbYear);

JButton btnAdd = makeBtn("Add", new Color(46,125,50), 30,


185);
JButton btnUpdate = makeBtn("Update", new Color(21,101,192), 145,
185);
JButton btnDelete = makeBtn("Delete", new Color(183,28,28), 260,
185);
JButton btnClear = makeBtn("Clear", new Color(97,97,97), 375,
185);
[Link](btnAdd); [Link](btnUpdate); [Link](btnDelete);
[Link](btnClear);
add(form, [Link]);

// 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]());
}
});

[Link](e -> clearFields());

167
}

private void loadTable() {


[Link](0);
try (Connection c = [Link]();
PreparedStatement ps = [Link]("SELECT * FROM
STUDENTS ORDER BY student_id");
ResultSet rs = [Link]()) {
while ([Link]())
[Link](new Object[]{
[Link]("student_id"), [Link]("student_name"),
[Link]("roll_no"), [Link]("department"),
[Link]("year")
});
} catch (SQLException ex) {
[Link](this, "Error: " +
[Link]());
}
}

private void clearFields() {


[Link](""); [Link](""); [Link]("");
[Link]("");
[Link](0);
}

private void addLabel(JPanel p, String t, int x, int y) {


JLabel l = new JLabel(t);
[Link](new Font("Segoe UI", [Link], 12));
[Link](x, y, 150, 20);
[Link](l);
}

private JTextField addField(JPanel p, int x, int y, int w, int h) {


JTextField f = new JTextField();
[Link](new Font("Segoe UI", [Link], 13));
[Link]([Link](
[Link](new Color(180,180,200)),
[Link](4,6,4,6)));
[Link](x, y, w, h);
[Link](f);
return f;
}

private JButton makeBtn(String t, Color bg, int x, int y) {


JButton b = new JButton(t);
[Link](new Font("Segoe UI", [Link], 12));
[Link](bg); [Link]([Link]);
[Link](false); [Link](false);
[Link](x, y, 105, 34);

168
[Link](new Cursor(Cursor.HAND_CURSOR));
return b;
}
}

Subject [Link]

package attendance;

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class SubjectForm extends JPanel {

private JTextField txtId, txtSubName, txtFaculty;


private JComboBox<String> cmbSemester;
private JTable table;
private DefaultTableModel tableModel;

public SubjectForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
buildUI();
loadTable();
}

private void buildUI() {


JPanel header = new JPanel(new BorderLayout());
[Link](new Color(0, 105, 92));
[Link](new Dimension(0, 50));
JLabel lbl = new JLabel(" Subject Management");
[Link](new Font("Segoe UI", [Link], 17));
[Link]([Link]);
[Link](lbl, [Link]);
add(header, [Link]);

JPanel form = new JPanel(null);


[Link]([Link]);
[Link](new Dimension(0, 195));

addLabel(form, "Subject ID:", 30, 30);


txtId = addField(form, 170, 28, 90, 30);
[Link](false); [Link](new
Color(230,230,230));

addLabel(form, "Subject Name *:", 310, 30);

169
txtSubName = addField(form, 450, 28, 220, 30);

addLabel(form, "Faculty Name *:", 30, 80);


txtFaculty = addField(form, 170, 78, 220, 30);

addLabel(form, "Semester *:", 450, 80);


cmbSemester = new JComboBox<>(new
String[]{"1","2","3","4","5","6","7","8"});
[Link](560, 78, 70, 30);
[Link](cmbSemester);

JButton btnAdd = makeBtn("Add", new Color(46,125,50), 30,


140);
JButton btnUpdate = makeBtn("Update", new Color(21,101,192), 145,
140);
JButton btnDelete = makeBtn("Delete", new Color(183,28,28), 260,
140);
JButton btnClear = makeBtn("Clear", new Color(97,97,97), 375,
140);
[Link](btnAdd); [Link](btnUpdate); [Link](btnDelete);
[Link](btnClear);
add(form, [Link]);

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]);

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]()); }
});

[Link](e -> clearFields());


}

private void loadTable() {


[Link](0);
try (Connection c = [Link]();
PreparedStatement ps = [Link]("SELECT * FROM
SUBJECTS ORDER BY subject_id");
ResultSet rs = [Link]()) {
while ([Link]())
[Link](new Object[]{
[Link]("subject_id"), [Link]("subject_name"),
[Link]("faculty_name"), [Link]("semester")
});
} catch (SQLException ex) { [Link](this,
"Error: " + [Link]()); }
}

private void clearFields() {


[Link](""); [Link](""); [Link]("");
[Link](0);
}

private void addLabel(JPanel p, String t, int x, int y) {


JLabel l = new JLabel(t); [Link](new Font("Segoe UI", [Link],
12));
[Link](x, y, 150, 20); [Link](l);
}
private JTextField addField(JPanel p, int x, int y, int w, int h) {
JTextField f = new JTextField(); [Link](new Font("Segoe UI",
[Link], 13));
[Link]([Link](
[Link](new Color(180,180,200)),
[Link](4,6,4,6)));
[Link](x, y, w, h); [Link](f); return f;
}
private JButton makeBtn(String t, Color bg, int x, int y) {
JButton b = new JButton(t); [Link](new Font("Segoe UI",
[Link], 12));
[Link](bg); [Link]([Link]);
[Link](false); [Link](false);
[Link](x, y, 105, 34); [Link](new
Cursor(Cursor.HAND_CURSOR)); return b;

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 {

private JTextField txtId, txtDate;


private JComboBox<Object> cmbStudent, cmbSubject;
private JComboBox<String> cmbStatus;
private JButton btnMark, btnUpdate, btnDelete, btnClear, btnRefresh;
private JTable table;
private DefaultTableModel tableModel;

public AttendanceForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));
buildUI();
populateCombos();
loadTable();
}

private void buildUI() {


// Header
JPanel header = new JPanel(new BorderLayout());
[Link](new Color(183, 28, 28));
[Link](new Dimension(0, 50));
JLabel lbl = new JLabel(" 📝 Attendance Marking");
[Link](new Font("Segoe UI", [Link], 17));
[Link]([Link]);
[Link](lbl, [Link]);
add(header, [Link]);

JPanel form = new JPanel(null);


[Link]([Link]);
[Link](new Dimension(0, 220));

173
[Link]([Link](0, 0, 1, 0, new
Color(220, 220, 220)));

addLabel(form, "Attendance ID (auto):", 20, 20);


txtId = addField(form, 210, 18, 80, 30);
[Link](false);
[Link](new Color(240, 240, 240));

addLabel(form, "Date (YYYY-MM-DD) *:", 340, 20);


txtDate = addField(form, 540, 18, 140, 30);
[Link](new SimpleDateFormat("yyyy-MM-dd").format(new
Date()));

addLabel(form, "Student *:", 20, 68);


cmbStudent = new JComboBox<>();
[Link](210, 66, 270, 30);
[Link](new Font("Segoe UI", [Link], 12));
[Link](cmbStudent);

addLabel(form, "Subject *:", 530, 68);


cmbSubject = new JComboBox<>();
[Link](640, 66, 250, 30);
[Link](new Font("Segoe UI", [Link], 12));
[Link](cmbSubject);

addLabel(form, "Status *:", 20, 116);


cmbStatus = new JComboBox<>(new String[]{"Present","Absent"});
[Link](210, 114, 140, 30);
[Link](new Font("Segoe UI", [Link], 13));
[Link](cmbStatus);

btnMark = makeBtn("✔ Mark", new Color(46, 125, 50), 20,


170);
btnUpdate = makeBtn("✏ Update", new Color(21, 101, 192), 140,
170);
btnDelete = makeBtn("🗑 Delete", new Color(183, 28, 28), 260,
170);
btnClear = makeBtn("🔄 Clear", new Color(97, 97, 97), 380,
170);
btnRefresh = makeBtn("🔃 Refresh",new Color(0, 131, 143), 500,
170);
[Link](btnMark); [Link](btnUpdate);
[Link](btnDelete); [Link](btnClear); [Link](btnRefresh);
add(form, [Link]);

// 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);

// Color rows by status


[Link]([Link], new
DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable t, Object
v, boolean sel, boolean foc, int row, int col) {
Component comp = [Link](t, v,
sel, foc, row, col);
if (!sel) {
String status = [Link](row,
5).toString();
if ("Present".equals(status))
[Link](new Color(232, 245, 233));
else
[Link](new Color(255, 235, 238));
}
return comp;
}
});

[Link](new MouseAdapter() {
public void mouseClicked(MouseEvent e) { rowToForm(); }
});
JScrollPane scroll = new JScrollPane(table);
[Link]([Link](10, 15, 15, 15));
add(scroll, [Link]);

[Link](e -> insert());


[Link](e -> update());
[Link](e -> delete());
[Link](e -> clearForm());
[Link](e -> { populateCombos(); loadTable();
});
}

private void populateCombos() {


[Link]();
[Link]();
try (Connection c = [Link]()) {
PreparedStatement ps = [Link]("SELECT
student_id,student_name,roll_no FROM STUDENTS ORDER BY student_name");
ResultSet rs = [Link]();
while ([Link]())
[Link]([Link]("student_id") + " – " +
[Link]("student_name") + " (" + [Link]("roll_no") + ")");

175
[Link](); [Link]();

ps = [Link]("SELECT subject_id,subject_name FROM


SUBJECTS ORDER BY subject_name");
rs = [Link]();
while ([Link]())
[Link]([Link]("subject_id") + " – " +
[Link]("subject_name"));
[Link](); [Link]();
} catch (SQLException ex) { showError(ex); }
}

private void insert() {


if (!checkFields()) return;
String sql = "INSERT INTO ATTENDANCE
(student_id,subject_id,attendance_date,status) VALUES(?,?,TO_DATE(?,'YYYY-
MM-DD'),?)";
try (Connection c = [Link]();
PreparedStatement ps = [Link](sql)) {
[Link](1, getId(cmbStudent));
[Link](2, getId(cmbSubject));
[Link](3, [Link]().trim());
[Link](4, (String) [Link]());
[Link]();
[Link](this, "Attendance marked
successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);
clearForm(); loadTable();
} catch (SQLException ex) { showError(ex); }
}

private void update() {


if ([Link]().isEmpty()) { warn("Select a row first.");
return; }
if (!checkFields()) return;
String sql = "UPDATE ATTENDANCE SET
student_id=?,subject_id=?,attendance_date=TO_DATE(?,'YYYY-MM-DD'),status=?
WHERE attendance_id=?";
try (Connection c = [Link]();
PreparedStatement ps = [Link](sql)) {
[Link](1, getId(cmbStudent));
[Link](2, getId(cmbSubject));
[Link](3, [Link]().trim());
[Link](4, (String) [Link]());
[Link](5, [Link]([Link]().trim()));
[Link]();
[Link](this, "Attendance updated!",
"Success", JOptionPane.INFORMATION_MESSAGE);
clearForm(); loadTable();
} catch (SQLException ex) { showError(ex); }
}

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); }
}

private void loadTable() {


[Link](0);
String sql = "SELECT a.attendance_id, st.student_name, st.roll_no,
su.subject_name, " +
"TO_CHAR(a.attendance_date,'YYYY-MM-DD') AS att_date,
[Link] " +
"FROM ATTENDANCE a " +
"JOIN STUDENTS st ON a.student_id=st.student_id " +
"JOIN SUBJECTS su ON a.subject_id=su.subject_id " +
"ORDER BY a.attendance_date DESC, a.attendance_id
DESC";
try (Connection c = [Link]();
PreparedStatement ps = [Link](sql);
ResultSet rs = [Link]()) {
while ([Link]())
[Link](new Object[]{
[Link]("attendance_id"),
[Link]("student_name"), [Link]("roll_no"),
[Link]("subject_name"), [Link]("att_date"),
[Link]("status")
});
} catch (SQLException ex) { showError(ex); }
}

private void rowToForm() {


int row = [Link]();
if (row == -1) return;
[Link]([Link](row, 0).toString());
[Link]([Link](row, 4).toString());
[Link]([Link](row,
5).toString());
String studentName = [Link](row, 1).toString();

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; }
}

private void clearForm() {


[Link]("");
[Link](new SimpleDateFormat("yyyy-MM-dd").format(new
Date()));
[Link](0);
if ([Link]() > 0) [Link](0);
if ([Link]() > 0) [Link](0);
}

private int getId(JComboBox<Object> cmb) {


return [Link]([Link]().toString().split(" –
")[0].trim());
}

private boolean checkFields() {


if ([Link]().trim().isEmpty()) { warn("Please enter a
date."); return false; }
if ([Link]() == 0 || [Link]() ==
0) { warn("No students or subjects found."); return false; }
if (![Link]().trim().matches("\\d{4}-\\d{2}-\\d{2}")) {
warn("Date must be YYYY-MM-DD."); return false; }
return true;
}

private void addLabel(JPanel p, String t, int x, int y) {


JLabel l = new JLabel(t);
[Link](new Font("Segoe UI", [Link], 12));
[Link](new Color(60, 60, 70));
[Link](x, y, 200, 20);
[Link](l);
}
private JTextField addField(JPanel p, int x, int y, int w, int h) {
JTextField f = new JTextField();
[Link](new Font("Segoe UI", [Link], 13));
[Link]([Link](
[Link](new Color(180, 180, 200)),
[Link](4, 6, 4, 6)));
[Link](x, y, w, h);
[Link](f);
return f;
}

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 class SubjectForm extends JPanel {

private JTextField txtId, txtSubName, txtFaculty;


private JComboBox<String> cmbSemester;
private JTable table;
private DefaultTableModel tableModel;

public SubjectForm() {
setLayout(new BorderLayout());
setBackground(new Color(245, 247, 250));

179
buildUI();
loadTable();
}

private void buildUI() {


JPanel header = new JPanel(new BorderLayout());
[Link](new Color(0, 105, 92));
[Link](new Dimension(0, 50));
JLabel lbl = new JLabel(" Subject Management");
[Link](new Font("Segoe UI", [Link], 17));
[Link]([Link]);
[Link](lbl, [Link]);
add(header, [Link]);

JPanel form = new JPanel(null);


[Link]([Link]);
[Link](new Dimension(0, 195));

addLabel(form, "Subject ID:", 30, 30);


txtId = addField(form, 170, 28, 90, 30);
[Link](false); [Link](new
Color(230,230,230));

addLabel(form, "Subject Name *:", 310, 30);


txtSubName = addField(form, 450, 28, 220, 30);

addLabel(form, "Faculty Name *:", 30, 80);


txtFaculty = addField(form, 170, 78, 220, 30);

addLabel(form, "Semester *:", 450, 80);


cmbSemester = new JComboBox<>(new
String[]{"1","2","3","4","5","6","7","8"});
[Link](560, 78, 70, 30);
[Link](cmbSemester);

JButton btnAdd = makeBtn("Add", new Color(46,125,50),


30, 140);
JButton btnUpdate = makeBtn("Update", new Color(21,101,192),
145, 140);
JButton btnDelete = makeBtn("Delete", new Color(183,28,28),
260, 140);
JButton btnClear = makeBtn("Clear", new Color(97,97,97),
375, 140);
[Link](btnAdd); [Link](btnUpdate); [Link](btnDelete);
[Link](btnClear);
add(form, [Link]);

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]()); }
});

[Link](e -> clearFields());

182
}

private void loadTable() {


[Link](0);
try (Connection c = [Link]();
PreparedStatement ps = [Link]("SELECT * FROM
SUBJECTS ORDER BY subject_id");
ResultSet rs = [Link]()) {
while ([Link]())
[Link](new Object[]{
[Link]("subject_id"),
[Link]("subject_name"),
[Link]("faculty_name"),
[Link]("semester")
});
} catch (SQLException ex) {
[Link](this, "Error: " + [Link]()); }
}

private void clearFields() {


[Link](""); [Link]("");
[Link]("");
[Link](0);
}

private void addLabel(JPanel p, String t, int x, int y) {


JLabel l = new JLabel(t); [Link](new Font("Segoe UI",
[Link], 12));
[Link](x, y, 150, 20); [Link](l);
}
private JTextField addField(JPanel p, int x, int y, int w, int h)
{
JTextField f = new JTextField(); [Link](new Font("Segoe
UI", [Link], 13));
[Link]([Link](
[Link](new Color(180,180,200)),
[Link](4,6,4,6)));
[Link](x, y, w, h); [Link](f); return f;
}
private JButton makeBtn(String t, Color bg, int x, int y) {
JButton b = new JButton(t); [Link](new Font("Segoe UI",
[Link], 12));
[Link](bg); [Link]([Link]);
[Link](false); [Link](false);
[Link](x, y, 105, 34); [Link](new
Cursor(Cursor.HAND_CURSOR)); return b;

183
}
}

Screenshots

184
185
186
187

You might also like