fields for username and password.
Only
Student the 'admin' user is allowed to access.
Attendance 2.2 Dashboard
The dashboard serves as the central hub
Application for navigating through the application's
functionalities. It features buttons for
Documentation adding students, marking attendance,
displaying attendance records, and
showing student names. The layout is
This documentation outlines the code organized with a side panel containing
structure and design of a Java-based navigation buttons and a main content
Student Attendance Application, which area that updates with the selected
allows administrators to manage student functionality.
attendance records, save to files, and
import/export data. The application 2.3 Add Student
provides a simple graphical user interface In this panel, new students can be added
(GUI) built using Swing and includes to the system by inputting their ID, name,
features like login, student management, guardian contact, and the current date
attendance marking, and data saving. and time. The application performs a
check to ensure the student ID is unique
before adding them to the student
1. Overview records. The data is saved to a file for
The Student Attendance Application is persistent storage.
built using Java's Swing framework for
the graphical interface. It utilizes various 2.4 Mark Attendance
Swing components like JFrame, JPanel, This functionality allows the
JLabel, JButton, JTextField, and JList for administrator to mark students as
user interactions. The core functionality 'Present' or 'Absent'. A search bar is
of the application revolves around provided to filter students, and a
managing students' attendance data and scrollable list displays students' details.
their details, such as student ID, name, Once a student is selected, attendance can
and guardian contact information. be marked accordingly.
2.5 Display Attendance
2. Key Components and Their This section divides the students into two
groups: Present and Absent. The
Functions
attendance records are displayed in two
2.1 Login System separate lists, and the data is color-coded
for clarity. A button is provided to save
The login system checks for an admin's
the attendance data to a file.
credentials. Upon successful login, the
user is granted access to the main
dashboard. The login screen includes
2.6 Save and Import Data 2.9 Source of code
The application supports saving student import javax.swing.*;
data and attendance to a file for import java.awt.*;
persistence. The data can also be import java.awt.event.ActionEvent;
imported from a file. The files are stored import java.awt.event.ActionListener;
in a specified directory, and paths can be import java.io.*;
customized during save operations. The import java.text.SimpleDateFormat;
application uses BufferedWriter and import java.util.*;
BufferedReader classes to handle file
operations efficiently. public class StudentAttendanceApp {
private Map<String, Boolean>
2.7 File Management attendanceRecord = new HashMap<>();
The system allows importing and private Map<String, String>
exporting of student data, which is stored guardianContacts = new HashMap<>();
as comma-separated values (CSV) files. private Map<String, String>
These files contain student IDs, names, studentNames = new TreeMap<>(); //
guardian contacts, and timestamps, Automatically sorts by key (Student ID)
allowing easy transfer of data. private Map<String, String>
studentTimestamps = new HashMap<>();
2.8 Design Principles private DefaultListModel<String>
The design of the application follows studentListModel = new
principles of simplicity and usability. The DefaultListModel<>();
layout is clean and organized, with private DefaultListModel<String>
distinct sections for each feature. The presentListModel = new
user interface is intuitive, providing clear DefaultListModel<>();
feedback on actions like login, adding private DefaultListModel<String>
students, marking attendance, and saving absentListModel = new
data. The application's backend is built to DefaultListModel<>();
handle data persistence via file private final String filePath = "C:\\
management. Users\\User\\Documents\\
bjstudents.txt"; // Path to save the
student data
public static void main(String[] args) {
new
StudentAttendanceApp().showLogin();
}
private void showLogin() {
JFrame frame = new JFrame("Login -
Student Attendance System");
loginButton.setBackground(new
frame.setDefaultCloseOperation(JFrame.E Color(50, 150, 250));
XIT_ON_CLOSE);
frame.setSize(400, 300); loginButton.setForeground(Color.WHITE)
frame.setLayout(new ;
BorderLayout()); loginButton.setFocusPainted(false);
centerPanel.add(new JLabel());
// Stylish Header centerPanel.add(loginButton);
JLabel titleLabel = new
JLabel("Student Attendance System", frame.add(centerPanel,
SwingConstants.CENTER); BorderLayout.CENTER);
titleLabel.setFont(new Font("Arial",
Font.BOLD, 20)); // Button Action
titleLabel.setForeground(new loginButton.addActionListener(e -> {
Color(50, 120, 200)); String username =
userText.getText();
titleLabel.setBorder(BorderFactory.creat String password = new
eEmptyBorder(20, 0, 20, 0)); String(passwordText.getPassword());
frame.add(titleLabel,
BorderLayout.NORTH); if (username.equals("admin") &&
password.equals("admin")) {
// Center Panel frame.dispose(); // Close the
JPanel centerPanel = new JPanel(new login frame
GridLayout(3, 2, 10, 10)); showDashboard(); // Show the
dashboard
centerPanel.setBorder(BorderFactory.cre } else {
ateEmptyBorder(20, 50, 20, 50));
JLabel userLabel = new JOptionPane.showMessageDialog(frame,
JLabel("Username:"); "Login Failed");
JTextField userText = new }
JTextField(); });
JLabel passwordLabel = new
JLabel("Password:"); frame.setVisible(true);
JPasswordField passwordText = new }
JPasswordField();
centerPanel.add(userLabel); private void showDashboard() {
centerPanel.add(userText); JFrame dashboardFrame = new
centerPanel.add(passwordLabel); JFrame("Dashboard - Student Attendance
centerPanel.add(passwordText); System");
// Login Button dashboardFrame.setDefaultCloseOperatio
JButton loginButton = new n(JFrame.EXIT_ON_CLOSE);
JButton("Login"); dashboardFrame.setSize(800, 600);
dashboardFrame.setLayout(new
BorderLayout()); // Content Panel
JPanel contentPanel = new JPanel();
// Header contentPanel.setLayout(new
JLabel dashboardTitle = new CardLayout());
JLabel("Student Attendance System", dashboardFrame.add(contentPanel,
SwingConstants.CENTER); BorderLayout.CENTER);
dashboardTitle.setFont(new
Font("Arial", Font.BOLD, 24)); // Define Panels for Features
dashboardTitle.setForeground(new JPanel addStudentPanel =
Color(50, 120, 200)); createAddStudentPanel();
JPanel markAttendancePanel =
dashboardTitle.setBorder(BorderFactory. createEnhancedMarkAttendancePanel();
createEmptyBorder(20, 0, 20, 0)); JPanel displayAttendancePanel =
dashboardFrame.add(dashboardTitle, createDisplayAttendancePanel();
BorderLayout.NORTH); JPanel displayStudentNamesPanel =
createDisplayStudentNamesPanel();
// Side Navigation Panel contentPanel.add(addStudentPanel,
JPanel sidePanel = new JPanel(new "AddStudent");
GridLayout(4, 1, 10, 10));
sidePanel.setBackground(new contentPanel.add(markAttendancePanel,
Color(240, 240, 240)); "MarkAttendance");
sidePanel.setBorder(BorderFactory.creat contentPanel.add(displayAttendancePane
eEmptyBorder(20, 20, 20, 20)); l, "DisplayAttendance");
JButton addStudentButton = new
JButton("Add Student"); contentPanel.add(displayStudentNamesP
JButton markAttendanceButton = anel, "DisplayStudentNames");
new JButton("Mark Attendance");
JButton displayAttendanceButton = // Button Actions to Switch Panels
new JButton("Display Attendance"); CardLayout cardLayout =
JButton displayStudentNamesButton (CardLayout) contentPanel.getLayout();
= new JButton("Display Student Names");
sidePanel.add(addStudentButton); addStudentButton.addActionListener(e ->
cardLayout.show(contentPanel,
sidePanel.add(markAttendanceButton); "AddStudent"));
sidePanel.add(displayAttendanceButton); markAttendanceButton.addActionListene
r(e -> cardLayout.show(contentPanel,
sidePanel.add(displayStudentNamesButt "MarkAttendance"));
on);
dashboardFrame.add(sidePanel, displayAttendanceButton.addActionListe
BorderLayout.WEST);
ner(e -> cardLayout.show(contentPanel, SimpleDateFormat formatter = new
"DisplayAttendance")); SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
displayStudentNamesButton.addActionLi
stener(e -> dateTimeText.setText(formatter.format(n
cardLayout.show(contentPanel, ew Date()));
"DisplayStudentNames"));
JButton addStudentButton = new
dashboardFrame.setVisible(true); JButton("Add Student");
} JButton clearButton = new
JButton("Clear");
private JPanel createAddStudentPanel() JButton saveButton = new
{ JButton("Save");
JPanel addStudentPanel = new JButton importFileButton = new
JPanel(); JButton("Import File");
addStudentPanel.setLayout(new
GridLayout(7, 2, 10, 10));
addStudentPanel.add(studentIdLabel);
addStudentPanel.setBorder(BorderFactor addStudentPanel.add(studentIdText);
y.createEmptyBorder(20, 50, 20, 50));
addStudentPanel.setBackground(new addStudentPanel.add(studentNameLabel)
Color(230, 240, 255)); ;
JLabel studentIdLabel = new addStudentPanel.add(studentNameText);
JLabel("Student ID:");
JTextField studentIdText = new addStudentPanel.add(guardianContactLa
JTextField(); bel);
JLabel studentNameLabel = new
JLabel("Student Name:"); addStudentPanel.add(guardianContactTe
JTextField studentNameText = new xt);
JTextField();
JLabel guardianContactLabel = new addStudentPanel.add(dateTimeLabel);
JLabel("Guardian Contact:"); addStudentPanel.add(dateTimeText);
JTextField guardianContactText =
new JTextField(); addStudentPanel.add(addStudentButton);
JLabel dateTimeLabel = new addStudentPanel.add(clearButton);
JLabel("Date & Time:"); addStudentPanel.add(saveButton);
JTextField dateTimeText = new
JTextField(); addStudentPanel.add(importFileButton);
dateTimeText.setEditable(false);
// Button Actions
// Auto-populate Date & Time field
addStudentButton.addActionListener(e -> markAttendancePanel.setBackground(ne
{ w Color(230, 240, 255));
String studentId =
studentIdText.getText(); // Search Bar
String studentName = JPanel searchPanel = new JPanel(new
studentNameText.getText(); FlowLayout());
String guardianContact = searchPanel.setBackground(new
guardianContactText.getText(); Color(230, 240, 255));
String dateTime = JTextField searchField = new
dateTimeText.getText(); JTextField(20);
addStudent(studentId, JButton searchButton = new
studentName, guardianContact, JButton("Search");
dateTime); searchPanel.add(new
}); JLabel("Search:"));
searchPanel.add(searchField);
clearButton.addActionListener(e -> { searchPanel.add(searchButton);
studentIdText.setText("");
studentNameText.setText(""); markAttendancePanel.add(searchPanel,
guardianContactText.setText(""); BorderLayout.NORTH);
dateTimeText.setText(formatter.format(n // Scrollable List
ew Date())); JList<String> studentList = new
}); JList<>(studentListModel);
saveButton.addActionListener(e -> studentList.setSelectionMode(ListSelectio
saveToFile()); nModel.SINGLE_SELECTION);
JScrollPane scrollPane = new
JScrollPane(studentList);
importFileButton.addActionListener(e ->
importFromFile()); markAttendancePanel.add(scrollPane,
BorderLayout.CENTER);
return addStudentPanel;
} // Mark Attendance Buttons
JPanel buttonPanel = new JPanel(new
private JPanel GridLayout(1, 2, 10, 10));
createEnhancedMarkAttendancePanel() {
JPanel markAttendancePanel = new buttonPanel.setBorder(BorderFactory.cre
JPanel(new BorderLayout()); ateEmptyBorder(20, 0, 0, 0));
JButton markPresentButton = new
markAttendancePanel.setBorder(BorderF JButton("Mark Present");
actory.createEmptyBorder(20, 50, 20, JButton markAbsentButton = new
50)); JButton("Mark Absent");
listPanel.setBackground(new
buttonPanel.add(markPresentButton); Color(230, 240, 255));
buttonPanel.add(markAbsentButton);
// Present Panel
markAttendancePanel.add(buttonPanel, JPanel presentPanel = new JPanel(new
BorderLayout.SOUTH); BorderLayout());
presentPanel.setBackground(new
// Button Actions Color(204, 255, 204)); // Light green for
searchButton.addActionListener(e -> present students
updateList(searchField.getText())); presentPanel.add(new JLabel("Present
Students:", SwingConstants.CENTER),
markPresentButton.addActionListener(e - BorderLayout.NORTH);
> JList<String> presentList = new
updateAttendance(studentList.getSelecte JList<>(presentListModel);
dValue(), true)); JScrollPane presentScrollPane = new
JScrollPane(presentList);
markAbsentButton.addActionListener(e - presentPanel.add(presentScrollPane,
> BorderLayout.CENTER);
updateAttendance(studentList.getSelecte
dValue(), false)); // Absent Panel
JPanel absentPanel = new JPanel(new
return markAttendancePanel; BorderLayout());
} absentPanel.setBackground(new
Color(255, 204, 204)); // Light red for
private JPanel absent students
createDisplayAttendancePanel() { absentPanel.add(new JLabel("Absent
JPanel displayAttendancePanel = new Students:", SwingConstants.CENTER),
JPanel(); BorderLayout.NORTH);
displayAttendancePanel.setLayout(new JList<String> absentList = new
BorderLayout(10, 10)); // Spacing JList<>(absentListModel);
between components JScrollPane absentScrollPane = new
JScrollPane(absentList);
displayAttendancePanel.setBorder(Borde absentPanel.add(absentScrollPane,
rFactory.createEmptyBorder(20, 50, 20, BorderLayout.CENTER);
50));
// Add both panels to the listPanel
displayAttendancePanel.setBackground(n listPanel.add(presentPanel);
ew Color(230, 240, 255)); listPanel.add(absentPanel);
// Create a main panel to hold the lists // Add the list panel to the main display
JPanel listPanel = new JPanel(new attendance panel
GridLayout(1, 2, 10, 10)); // Adjust grid displayAttendancePanel.add(listPanel,
for two columns BorderLayout.CENTER);
JPanel displayStudentNamesPanel =
// Save Button Panel (bottom-left new JPanel(new BorderLayout());
corner)
JPanel buttonPanel = new JPanel(new displayStudentNamesPanel.setBorder(Bo
FlowLayout(FlowLayout.LEFT)); rderFactory.createEmptyBorder(20, 50,
buttonPanel.setBackground(new 20, 50));
Color(230, 240, 255));
displayStudentNamesPanel.setBackgroun
JButton saveAttendanceButton = new d(new Color(230, 240, 255));
JButton("Save Attendance");
// Student Names List
saveAttendanceButton.setBackground(ne displayStudentNamesPanel.add(new
w Color(50, 150, 250)); JLabel("All Students:"),
BorderLayout.NORTH);
saveAttendanceButton.setForeground(Col JList<String> studentList = new
or.WHITE); JList<>(studentListModel);
JScrollPane scrollPane = new
saveAttendanceButton.setFocusPainted(f JScrollPane(studentList);
alse);
displayStudentNamesPanel.add(scrollPan
// Button Action for Saving Attendance e, BorderLayout.CENTER);
saveAttendanceButton.addActionListener return displayStudentNamesPanel;
(e -> saveAttendanceToFile()); }
// Add the save button to the private void addStudent(String
buttonPanel studentId, String studentName, String
guardianContact, String dateTime) {
buttonPanel.add(saveAttendanceButton); if (!
attendanceRecord.containsKey(studentId
// Add the buttonPanel to the bottom of )) {
the displayAttendancePanel attendanceRecord.put(studentId,
false);
displayAttendancePanel.add(buttonPanel, guardianContacts.put(studentId,
BorderLayout.SOUTH); guardianContact);
studentNames.put(studentId,
return displayAttendancePanel; studentName);
} studentTimestamps.put(studentId,
dateTime);
updateStudentLists();
private JPanel
createDisplayStudentNamesPanel() { JOptionPane.showMessageDialog(null,
"Student Added Successfully!");
} else {
JOptionPane.showMessageDialog(null,
JOptionPane.showMessageDialog(null, "Please select a student.");
"Student already exists."); }
} }
}
private void updateList(String query) {
private void updateStudentLists() { studentListModel.clear();
studentListModel.clear(); for (String studentId :
presentListModel.clear(); studentNames.keySet()) {
absentListModel.clear(); if
(studentId.toLowerCase().contains(query.
for (String studentId : toLowerCase()) ||
studentNames.keySet()) { studentNames.get(studentId).toLowerCas
String entry = studentId + " - " + e().contains(query.toLowerCase())) {
studentNames.get(studentId) + " [" + String entry = studentId + " - " +
studentTimestamps.get(studentId) + "]"; studentNames.get(studentId) + " [" +
studentTimestamps.get(studentId) + "]";
studentListModel.addElement(entry);
studentListModel.addElement(entry);
if }
(attendanceRecord.get(studentId)) { }
}
presentListModel.addElement(entry);
} else { private void saveToFile() {
try (BufferedWriter writer = new
absentListModel.addElement(entry); BufferedWriter(new
} FileWriter(filePath))) {
} for (String studentId :
} studentNames.keySet()) {
writer.write(studentId + "," +
private void updateAttendance(String studentNames.get(studentId) + "," +
selectedValue, boolean isPresent) { guardianContacts.get(studentId) + "," +
if (selectedValue != null) { studentTimestamps.get(studentId));
String studentId = writer.newLine();
selectedValue.split(" - ")[0]; }
attendanceRecord.put(studentId,
isPresent); JOptionPane.showMessageDialog(null,
updateStudentLists(); "Student data saved successfully to file.");
} catch (IOException e) {
JOptionPane.showMessageDialog(null,
"Attendance updated."); JOptionPane.showMessageDialog(null,
} else { "Error saving file: " + e.getMessage());
} for (String studentId :
} attendanceRecord.keySet()) {
String attendanceStatus =
private void importFromFile() { attendanceRecord.get(studentId) ?
try (BufferedReader reader = new "Present" : "Absent";
BufferedReader(new
FileReader(filePath))) { String studentName =
String line; studentNames.get(studentId);
while ((line = reader.readLine()) != String timestamp =
null) { studentTimestamps.get(studentId);
String[] parts = line.split(","); writer.write(studentId + "," +
if (parts.length == 4) { studentName + "," + attendanceStatus +
addStudent(parts[0], parts[1], "," + timestamp);
parts[2], parts[3]); writer.newLine();
} }
}
JOptionPane.showMessageDialog(null,
JOptionPane.showMessageDialog(null, "Attendance data saved successfully to
"Student data imported successfully."); file.");
} catch (IOException e) { } catch (IOException e) {
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
"Error importing file: " + e.getMessage()); "Error saving attendance file: " +
} e.getMessage());
} }
private void saveAttendanceToFile() { }
String customFilePath =
JOptionPane.showInputDialog("Enter the }
file path to save attendance data:");
// Check if the file path is null or empty.
If it is, default to the specified path.
if (customFilePath == null ||
customFilePath.isEmpty()) {
customFilePath = "D:\\Download\\
ProjectBj\\attendance_data.txt"; //
Default file path
}
try (BufferedWriter writer = new
BufferedWriter(new
FileWriter(customFilePath))) {