0% found this document useful (0 votes)
8 views40 pages

Project 12

oop sample project

Uploaded by

Windtaker
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)
8 views40 pages

Project 12

oop sample project

Uploaded by

Windtaker
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
You are on page 1/ 40

Prepared For

Maam’ Iqra Sarfraz

COMSATS University, Abbotabbad Campus

Prepared By

Muhammad Osama (SP23-BCS-074)

Project description

University Attendance System Website

This project is a comprehensive university attendance system designed to streamline


the academic management process. It features three distinct user roles: student,
teacher, and admin.
 Student Features:

o Course Management: Students can easily select and remove courses


from their profiles.
o Assignment and Attendance Tracking: Students can view their
assignments and monitor their attendance records.
o Teacher Selection: Students have the option to pick their preferred
teachers for various courses.
 Teacher Features:

o Attendance Management: Teachers can add and update the attendance


of their students.
o Grading: Teachers have the capability to mark student performance and
upload grades.
 Admin Features:

Full Access: The admin has comprehensive control over the system, including
managing courses, students, and teachers, as well as overseeing the entire academic
process

Main Class
package view;

import view.forms.LoginUI;

import javax.swing.*;

import com.formdev.flatlaf.FlatLightLaf;

public class UAS {

public static void main(String[] args) {

try {

UIManager.setLookAndFeel(new FlatLightLaf());

} catch (UnsupportedLookAndFeelException e) {

}
LoginUI loginScreen = new LoginUI();

loginScreen.setVisible(true);

Class Dashboard
package view;

import view.forms.UserSettings;
import view.components.ViewAttendance;

import view.components.ModifyAttendance;

import view.forms.DeleteAttendance;

import view.forms.AddAttendance;

import view.components.Reports;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import controller.UASController;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import view.components.charts.SemesterAttendanceReport;

import view.forms.LoginUI;

public class Dashboard extends JFrame {


private JPanel headerPanel;

private JPanel menuPanel;

private JPanel contentPanel;

public Dashboard() {

if (!UASController.isUserLoggedIn()) {

LoginUI loginScreen = new LoginUI();


loginScreen.setVisible(true);

this.dispose();

} else {

if(UASController.objApplicationSession.getUser().getRole().equals("faculty"))

setTitle("University Attendance System -Faculty Dashboard");

else

setTitle("University Attendance System -Student Dashboard");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setExtendedState(JFrame.MAXIMIZED_BOTH);

setLayout(new BorderLayout());

// Header Panel

createHeaderPanel();

// Menu Panel
createMenuPanel();

// Content Panel

createContentPanel();
pack();

setLocationRelativeTo(null);

private void createHeaderPanel() {

headerPanel = new JPanel();


headerPanel.setBackground(new Color(41, 128, 185));

headerPanel.setLayout(new BorderLayout());

headerPanel.setPreferredSize(new Dimension(800, 75));

add(headerPanel, BorderLayout.NORTH);

JLabel titleLabel = new JLabel("University Attendance System");

titleLabel.setForeground(new Color(250, 250, 250));

titleLabel.setFont(new Font("Arial", Font.BOLD, 24));

titleLabel.setVerticalAlignment(SwingConstants.CENTER);

titleLabel.setHorizontalAlignment(SwingConstants.CENTER);

headerPanel.add(titleLabel, BorderLayout.CENTER);

private void createMenuPanel() {


menuPanel = new JPanel();

menuPanel.setBackground(new Color(52, 152, 219));

menuPanel.setPreferredSize(new Dimension(220, 600));

menuPanel.setLayout(new GridBagLayout());
add(menuPanel, BorderLayout.WEST);

GridBagConstraints gbc = new GridBagConstraints();

gbc.gridx = 0;

gbc.gridy = 0;

gbc.insets = new Insets(10, 10, 10, 10);

if(UASController.objApplicationSession.getUser().getRole().equals("student")){

JButton homeButton = createMenuButton("Dashboard");

JButton viewAttendanceButton = createMenuButton("View Attendance");

menuPanel.add(homeButton, gbc);

gbc.gridy++;

menuPanel.add(viewAttendanceButton, gbc);

gbc.gridy++;

if (UASController.objApplicationSession.getUser().getRole().equals("faculty")) {
JButton addAttendanceButton = createMenuButton("Add Attendance");

JButton deleteAttendanceButton = createMenuButton("Delete Attendance");

JButton modifyAttendanceButton = createMenuButton("Modify Attendance");

menuPanel.add(addAttendanceButton, gbc);

gbc.gridy++;

menuPanel.add(deleteAttendanceButton, gbc);

gbc.gridy++;
menuPanel.add(modifyAttendanceButton, gbc);

gbc.gridy++;

JButton settingsButton = createMenuButton("User Settings");

if(UASController.objApplicationSession.getUser().getRole().equals("student")){

JButton reportsButton = createMenuButton("Reports");

menuPanel.add(reportsButton, gbc);

gbc.gridy++;

menuPanel.add(settingsButton, gbc);

gbc.gridy++;

gbc.gridy++;

JButton logoutButton = new JButton("Logout");

logoutButton.setForeground(Color.WHITE);

logoutButton.setBackground(new Color(41, 128, 185));

logoutButton.setFocusPainted(false);
logoutButton.setFont(new Font("Arial", Font.BOLD, 12));

logoutButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

logoutButton.putClientProperty("JButton.buttonType", "roundRect"); // Use


roundRect button type

logoutButton.putClientProperty("JButton.selectedBackground", new Color(52, 152,


219));

// Add ActionListener to handle logout functionality


logoutButton.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {

UASController.expireSession();

});

menuPanel.add(logoutButton, gbc);

private JButton createMenuButton(String text) {

JButton button = new JButton(text);

button.setPreferredSize(new Dimension(200, 35));

button.setForeground(Color.WHITE);

button.setBackground(new Color(41, 128, 185));

button.setFocusPainted(false);

button.setFont(new Font("Arial", Font.BOLD, 14));

button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

button.putClientProperty("JButton.buttonType", "roundRect"); // Use roundRect


button type
button.putClientProperty("JButton.selectedBackground", new Color(52, 152, 219));

// Add WindowListener to handle closing event

addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

// Call the method to expire the session and handle any other necessary
cleanup
UASController.expireSession();
}

});

// Hover Effect

button.addMouseListener(new java.awt.event.MouseAdapter() {

});

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Handle button click event or navigate to the corresponding page

String buttonText = button.getText();

contentPanel.removeAll();

if (buttonText.equals("Dashboard")) {

contentPanel.add(new SemesterAttendanceReport(),
BorderLayout.CENTER);

} else if (buttonText.equals("Add Attendance")) {

contentPanel.add(new AddAttendance());

} else if (buttonText.equals("View Attendance")) {

contentPanel.add(new ViewAttendance());
} else if (buttonText.equals("Delete Attendance")) {

contentPanel.add(new DeleteAttendance());

} else if (buttonText.equals("Modify Attendance")) {

contentPanel.add(new ModifyAttendance());

} else if (buttonText.equals("User Settings")) {

contentPanel.add(new UserSettings());

} else if (buttonText.equals("Reports")) {

contentPanel.add(new Reports());

contentPanel.revalidate();

contentPanel.repaint();
}

});

return button;

private void createContentPanel() {

contentPanel = new JPanel();


contentPanel.setLayout(new BorderLayout()); // Set layout manager for the content
panel

if(UASController.objApplicationSession.getUser().getRole().equals("student")){
contentPanel.add(new SemesterAttendanceReport(), BorderLayout.CENTER); //
Add the chart to the center of the content panel

}else{

contentPanel.add(new AddAttendance(), BorderLayout.CENTER); // Add the


chart to the center of the content panel
}

add(contentPanel, BorderLayout.CENTER);

Admin_dashboard

package view;

/**

* @author fawad

*/

import view.components.UTCTime;
import javax.swing.*;

import controller.UASController;

import japa.parser.ParseException;

import java.awt.*;
import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.swing.JFrame;

import view.forms.LoginUI;
import view.components.ManageCourses;

import view.components.ManageStudents;

import view.components.ManageTeachers;

import view.components.ManageUsers;

import view.forms.AssignmentDashboard;

public class AdminDashboard extends JFrame {

private JPanel headerPanel;

private JPanel menuPanel;

private JPanel contentPanel;

public AdminDashboard() {

if (!UASController.isUserLoggedIn()) {

LoginUI loginScreen = new LoginUI();


loginScreen.setVisible(true);

this.dispose();

} else {
setTitle("Attendance Management System - Admin Dashboard");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setExtendedState(JFrame.MAXIMIZED_BOTH);

setLayout(new BorderLayout());

// Header Panel

createHeaderPanel();

// Menu Panel

createMenuPanel();

// Content Panel

createContentPanel();

pack();

setLocationRelativeTo(null);

private void createHeaderPanel() {

headerPanel = new JPanel();

headerPanel.setBackground(new Color(41, 128, 185));


headerPanel.setLayout(new BorderLayout());

headerPanel.setPreferredSize(new Dimension(800, 75));

add(headerPanel, BorderLayout.NORTH);

// Add WindowListener to handle closing event


addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

// Call the method to expire the session and handle any other necessary
cleanup

UASController.expireSession();

});

JLabel titleLabel = new JLabel("Admin Dashboard");

titleLabel.setForeground(new Color(250, 250, 250));

titleLabel.setFont(new Font("Arial", Font.BOLD, 24));

titleLabel.setVerticalAlignment(SwingConstants.CENTER);

titleLabel.setHorizontalAlignment(SwingConstants.CENTER);

headerPanel.add(titleLabel, BorderLayout.CENTER);

JPanel rightPanel = new JPanel(new BorderLayout());

rightPanel.setOpaque(false);
headerPanel.add(rightPanel, BorderLayout.EAST);

JLabel timeLabel = new JLabel();

timeLabel.setForeground(new Color(250, 250, 250));

timeLabel.setFont(new Font("Arial", Font.BOLD, 18));

rightPanel.add(timeLabel, BorderLayout.NORTH);

// Update the time label using the UTCTime class

Thread updateTimeThread = new Thread(() -> {


while (true) {

try {

Date utcTime = UTCTime.getCurrentUtcTime();

String formattedTime = new


SimpleDateFormat("HH:mm:ss").format(utcTime);

SwingUtilities.invokeLater(() -> timeLabel.setText("UTC Time: " +


formattedTime));

Thread.sleep(1000); // Update every second

} catch (InterruptedException | ParseException e) {

});

updateTimeThread.start();

private void createMenuPanel() {

menuPanel = new JPanel();

menuPanel.setBackground(new Color(52, 152, 219));

menuPanel.setPreferredSize(new Dimension(220, 600));

menuPanel.setLayout(new GridBagLayout());

add(menuPanel, BorderLayout.WEST);

GridBagConstraints gbc = new GridBagConstraints();

gbc.gridx = 0;

gbc.gridy = 0;
gbc.insets = new Insets(10, 10, 10, 10);
// JButton addStudentButton = createMenuButton("Add Student");

// menuPanel.add(addStudentButton, gbc);

// gbc.gridy++;

JButton manageStudentsButton = createMenuButton("Manage Students");

menuPanel.add(manageStudentsButton, gbc);

gbc.gridy++;

JButton manageCourseButton = createMenuButton("Manage Courses");


menuPanel.add(manageCourseButton, gbc);

gbc.gridy++;

JButton manageUserButton = createMenuButton("Manage Users");

menuPanel.add(manageUserButton, gbc);

gbc.gridy++;

JButton manageTeacherButton = createMenuButton("Manage Teachers");

menuPanel.add(manageTeacherButton, gbc);

gbc.gridy++;

JButton assignCourseTeacherButton = createMenuButton("Assignment


Dashboard");
menuPanel.add(assignCourseTeacherButton, gbc);
gbc.gridy++;

gbc.gridy++;

JButton logoutButton = new JButton("Logout");

logoutButton.setForeground(Color.WHITE);

logoutButton.setBackground(new Color(41, 128, 185));

logoutButton.setFocusPainted(false);

logoutButton.setFont(new Font("Arial", Font.BOLD, 12));


logoutButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

logoutButton.putClientProperty("JButton.buttonType", "roundRect"); // Use


roundRect button type
logoutButton.putClientProperty("JButton.selectedBackground", new Color(52, 152,
219));

// Add ActionListener to handle logout functionality

logoutButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

UASController.expireSession();

});

menuPanel.add(logoutButton, gbc);

private JButton createMenuButton(String text) {

JButton button = new JButton(text);

button.setPreferredSize(new Dimension(200, 35));

button.setForeground(Color.WHITE);

button.setBackground(new Color(41, 128, 185));

button.setFocusPainted(false);

button.setFont(new Font("Arial", Font.BOLD, 14));

button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

button.putClientProperty("JButton.buttonType", "roundRect"); // Use roundRect


button type

button.putClientProperty("JButton.selectedBackground", new Color(52, 152, 219));


// Hover Effect

button.addMouseListener(new java.awt.event.MouseAdapter() {

});

button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

// Handle button click event or navigate to the corresponding page

String buttonText = button.getText();

contentPanel.removeAll();

if (buttonText.equals("Manage Courses")) {

contentPanel.add(new ManageCourses());

} else if (buttonText.equals("Manage Users")) {

contentPanel.add(new ManageUsers());

} else if (buttonText.equals("Manage Students")) {

contentPanel.add(new ManageStudents());
}else if (buttonText.equals("Manage Teachers")) {

contentPanel.add(new ManageTeachers());

} else if (buttonText.equals("Assignment Dashboard")) {

contentPanel.add(new AssignmentDashboard());
}

contentPanel.revalidate();
contentPanel.repaint();

});

return button;

private void createContentPanel() {

contentPanel = new JPanel();

contentPanel.setLayout(new BorderLayout());

add(contentPanel, BorderLayout.CENTER);

String[] parts =
UASController.objApplicationSession.getUser().getEmail().split("@");

String username = parts[0];

JLabel welcomeLabel = new JLabel("Hey there " + username + "!");

welcomeLabel.setFont(new Font("Arial", Font.BOLD, 20));

welcomeLabel.setForeground(new Color(41, 128, 185));

welcomeLabel.setHorizontalAlignment(SwingConstants.CENTER);
contentPanel.add(welcomeLabel, BorderLayout.CENTER);
}

Courses.java

package view.components;
/**

* @author fawad

*/

import controller.UASController;

import javax.swing.*;

import javax.swing.table.DefaultTableModel;

import java.awt.*;
import java.util.ArrayList;

import model.UASFactory;

import model.dto.CourseDTO;

import model.dto.Response;

public class Courses extends JPanel {

private JTable table;

UASController objController;

public Courses() {

objController=UASFactory.getUASControllerInstance();
setLayout(new BorderLayout());

// Create the table model with column names

String[] columnNames = {"Course Code", "Course Name", "Credit Hours"};


DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);

Response response=UASFactory.getResponseInstance();

ArrayList<CourseDTO> courseList=objController.getCourses(response);

for(CourseDTO c:courseList){
tableModel.addRow(new Object[]{

c.getCourseCode(),

c.getCourseName(),

c.getCreditHours()

});

// Create the table with the model

table = new JTable(tableModel);

// Add the table to a scroll pane

JScrollPane scrollPane = new JScrollPane(table);

// Add the scroll pane to the panel

add(scrollPane, BorderLayout.CENTER);

Managecourse.java

package view.components;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import view.forms.AddCourse;
import static view.components.Component.createMenuButton;
public class ManageCourses extends JPanel {

private CardLayout cardLayout;

private JPanel cardPanel;

private JPanel addCoursePanel;

private JPanel viewCoursesPanel;

public ManageCourses() {

setLayout(new BorderLayout());

// Create the card layout and the card panel to hold the panels

cardLayout = new CardLayout();

cardPanel = new JPanel(cardLayout);

// Create the AddCourse panel and add it to the card panel

addCoursePanel = new AddCourse();

cardPanel.add(addCoursePanel, "AddCourse");

// Add the card panel to the main panel

add(cardPanel, BorderLayout.CENTER);

// Create a navigation bar with buttons to switch between panels

JPanel navBarPanel = new JPanel();

navBarPanel.setLayout(new BoxLayout(navBarPanel, BoxLayout.X_AXIS));

JButton addCourseButton = createMenuButton("Add Course");

JButton viewCoursesButton = createMenuButton("View Courses");


// Apply styles to the navigation bar

navBarPanel.setBackground(new Color(173, 216, 230)); // Light blue background


color
navBarPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); //
Margin and padding

addCourseButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

cardLayout.show(cardPanel, "AddCourse");

});

viewCoursesButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Create the ViewCourses panel and add it to the cardPanel

viewCoursesPanel = new Courses();

cardPanel.add(viewCoursesPanel, "ViewCourses");

cardLayout.show(cardPanel, "ViewCourses");

});

// Add a gap of 10 pixels between the buttons

navBarPanel.add(addCourseButton);
navBarPanel.add(Box.createHorizontalStrut(10)); // Add a gap of 10 pixels
navBarPanel.add(viewCoursesButton);

// Add the navigation bar panel to the main panel

add(navBarPanel, BorderLayout.NORTH);

Manageteacher.java
package view.components;
import view.forms.AddTeacher;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import static view.components.Component.createMenuButton;

public class ManageTeachers extends JPanel {

private CardLayout cardLayout;


private JPanel cardPanel;

private JPanel addTeacherPanel;

private JPanel manageTeachersPanel;

public ManageTeachers() {

setLayout(new BorderLayout());

// Create the card layout and the card panel to hold the panels

cardLayout = new CardLayout();


cardPanel = new JPanel(cardLayout);

// Create the AddTeacher panel and add it to the card panel

addTeacherPanel = new AddTeacher();

cardPanel.add(addTeacherPanel, "AddTeacher");

// Add the card panel to the main panel

add(cardPanel, BorderLayout.CENTER);

// Create a navigation bar with buttons to switch between panels

JPanel navBarPanel = new JPanel();

navBarPanel.setLayout(new BoxLayout(navBarPanel, BoxLayout.X_AXIS));

JButton addTeacherButton = createMenuButton("Add Teacher");

JButton viewTeachersButton = createMenuButton("View Teachers");

// Apply styles to the navigation bar

navBarPanel.setBackground(new Color(173, 216, 230)); // Light blue background


color
navBarPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); //
Margin and padding

addTeacherButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Create the AddTeacher panel and add it to the cardPanel

cardLayout.show(cardPanel, "AddTeacher");
}
});

viewTeachersButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Create the ViewTeachers panel and add it to the cardPanel

manageTeachersPanel = new ViewTeachers();


cardPanel.add(manageTeachersPanel, "ViewTeachers");

cardLayout.show(cardPanel, "ViewTeachers");

});

// Add the buttons to the navigation bar panel in the desired order

navBarPanel.add(addTeacherButton);

navBarPanel.add(Box.createHorizontalStrut(10)); // Add a gap of 10 pixels

navBarPanel.add(viewTeachersButton);

// Add the navigation bar panel to the main panel

add(navBarPanel, BorderLayout.NORTH);

Manageuser.java
package view.components;

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import static view.components.Component.createMenuButton;

import view.forms.AddUser;

public class ManageUsers extends JPanel {

private CardLayout cardLayout;


private JPanel cardPanel;

public ManageUsers() {

setLayout(new BorderLayout());

// Create the card layout and the card panel to hold the panels

cardLayout = new CardLayout();

cardPanel = new JPanel(cardLayout);

add(cardPanel, BorderLayout.CENTER);

// Create a navigation bar with buttons to switch between panels


JPanel navBarPanel = new JPanel();

navBarPanel.setLayout(new BoxLayout(navBarPanel, BoxLayout.X_AXIS));

navBarPanel.setBackground(new Color(173, 216, 230)); // Light blue background


color

navBarPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); //


Margin and padding

JButton addUserButton = createMenuButton("Add User");


JButton viewUsersButton = createMenuButton("View Users");
AddUser addUserPanel = new AddUser();

cardPanel.add(addUserPanel, "AddUser");

addUserButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Create the AddUser panel and add it to the cardPanel

cardLayout.show(cardPanel, "AddUser");
}

});

viewUsersButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Create the ViewUsers panel and add it to the cardPanel

ViewUsers viewUsersPanel = new ViewUsers();

cardPanel.add(viewUsersPanel, "ViewUsers");

cardLayout.show(cardPanel, "ViewUsers");

}
});

// Add the buttons to the navigation bar panel in the desired order

navBarPanel.add(addUserButton);
navBarPanel.add(Box.createHorizontalStrut(10)); // Add a gap of 10 pixels

navBarPanel.add(viewUsersButton);

// Add the navigation bar panel to the main panel


add(navBarPanel, BorderLayout.NORTH);

Modifyattandance
package view.components;

import org.jdatepicker.JDatePicker;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Date;

public class ModifyAttendance extends JPanel {

private JLabel courseLabel;


private JComboBox<String> courseComboBox;

private JLabel dateLabel;

private JDatePicker datePicker;

private JLabel remarksLabel;

private JTextField remarksField;

private JTable attendanceTable;


private JButton updateAttendanceButton;

public ModifyAttendance() {
initializeComponents();

setupLayout();

addListeners();

private void initializeComponents() {


courseLabel = new JLabel("Course:");

courseComboBox = new JComboBox<>(new String[]{"Data Structures", "OOSE",


"Statistics"});

dateLabel = new JLabel("Date:");

datePicker = new JDatePicker(new Date());

remarksLabel = new JLabel("Remarks:");

remarksField = new JTextField(20);

updateAttendanceButton = new JButton("Update Attendance");

attendanceTable = new JTable();


}

private void setupLayout() {

setLayout(new GridBagLayout());

setOpaque(false);

GridBagConstraints gbc = new GridBagConstraints();

gbc.fill = GridBagConstraints.HORIZONTAL;

gbc.insets = new Insets(5, 5, 5, 5);


// Add course label and combo box

gbc.gridx = 0;

gbc.gridy = 0;

add(courseLabel, gbc);

gbc.gridx = 1;

add(courseComboBox, gbc);

// Add date label and date picker

gbc.gridx = 0;

gbc.gridy = 1;

add(dateLabel, gbc);

gbc.gridx = 1;

add(datePicker, gbc);

// Add remarks label and text field

gbc.gridx = 0;
gbc.gridy = 2;

add(remarksLabel, gbc);

gbc.gridx = 1;
add(remarksField, gbc);

// Add update attendance button

gbc.gridx = 0;
gbc.gridy = 3;

gbc.gridwidth = 2;

gbc.weighty = 0;

gbc.fill = GridBagConstraints.CENTER;

gbc.anchor = GridBagConstraints.CENTER;

add(updateAttendanceButton, gbc);

// Add attendance table


gbc.gridx = 0;

gbc.gridy = 4;

gbc.gridwidth = 2;

gbc.weightx = 1;

gbc.weighty = 1;

gbc.fill = GridBagConstraints.BOTH;

JScrollPane scrollPane = new JScrollPane(attendanceTable);

add(scrollPane, gbc);

private void addListeners() {


updateAttendanceButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

String selectedCourse = (String) courseComboBox.getSelectedItem();


// You can get the selected date in a similar way to the "ViewAttendance"
panel

String remarks = remarksField.getText();


// Get the updated attendance information from the table

DefaultTableModel tableModel = (DefaultTableModel)


attendanceTable.getModel();
int rowCount = tableModel.getRowCount();

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

String name = (String) tableModel.getValueAt(i, 0);

String regNo = (String) tableModel.getValueAt(i, 1);

boolean isPresent = (Boolean) tableModel.getValueAt(i, 2);

// Perform attendance update logic here

System.out.println("Name: " + name + ", RegNo: " + regNo + ", Present: " +
isPresent);
}

// Clear input fields

remarksField.setText("");

// Clear table selection

attendanceTable.clearSelection();

});

Viewattandancejava
/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this
template

*/

package view.components;

import javax.swing.*;

import javax.swing.table.DefaultTableCellRenderer;

import javax.swing.table.DefaultTableModel;

import java.awt.*;

import java.text.SimpleDateFormat;
import java.util.Date;

import java.awt.GridBagConstraints;

import controller.UASController;

import org.jdatepicker.JDatePicker;

public class ViewAttendance extends JPanel {

private JLabel courseLabel;

private JComboBox<String> courseComboBox;

private JLabel dateLabel;

private JDatePicker datePicker;

private JButton viewAttendanceButton;

private JTable attendanceTable;


public ViewAttendance() {

initializeComponents();

setupLayout();

addListeners();

private void initializeComponents() {

courseLabel = new JLabel("Course:");

courseComboBox = new JComboBox<>(new String[]{"Data Structures", "OOSE",


"Statistics"});

dateLabel = new JLabel("Date:");

datePicker = new JDatePicker(new Date());

viewAttendanceButton = new JButton("View Attendance");

attendanceTable = new JTable();

private void setupLayout() {

setLayout(new GridBagLayout());

setOpaque(false);

GridBagConstraints gbc = new GridBagConstraints();

gbc.fill = GridBagConstraints.HORIZONTAL;

gbc.insets = new Insets(5, 5, 5, 5);


// Add course label and combo box

gbc.gridx = 0;

gbc.gridy = 0;

add(courseLabel, gbc);

gbc.gridx = 1;

add(courseComboBox, gbc);

// Add date label and date picker

gbc.gridx = 0;

gbc.gridy = 1;

add(dateLabel, gbc);

gbc.gridx = 1;

add(datePicker, gbc);

// Add view attendance button

gbc.gridx = 0;

gbc.gridy = 2;
gbc.gridwidth = 2;

gbc.weighty = 0;

gbc.fill = GridBagConstraints.CENTER;

gbc.anchor = GridBagConstraints.CENTER;
add(viewAttendanceButton, gbc);

// Add attendance table

gbc.gridx = 0;
gbc.gridy = 3;

gbc.gridwidth = 2;

gbc.weightx = 1;

gbc.weighty = 1;

gbc.fill = GridBagConstraints.BOTH;

JScrollPane scrollPane = new JScrollPane(attendanceTable);

add(scrollPane, gbc);

private void addListeners() {

viewAttendanceButton.addActionListener(e -> {

String selectedCourse = (String) courseComboBox.getSelectedItem();

Date selectedDate = (Date) datePicker.getModel().getValue();

System.out.println("Selected Course: " + selectedCourse);

System.out.println("Selected Date: " + selectedDate);

// Query attendance records based on selected course and date

// Update the attendanceTable with the retrieved data

DefaultTableModel tableModel = new DefaultTableModel();


// Populate the table model with the retrieved attendance records

// tableModel.addColumn("Column Name"); // Add columns to the table model

// tableModel.addRow(new Object[]{"Value 1", "Value 2", ...}); // Add rows to the


table model

attendanceTable.setModel(tableModel);

});

}
Class diagram
Package diagram (below)

Portal login
Database

You might also like