Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Student Attendance System
- * Object Oriented Programming
- * P03
- * Nicholas Leong
- * 1002827B
- */
- //Import required GUI files
- import java.util.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.Vector;
- public class AttendanceGUI {
- JTextField usernameEntry, passwordEntry;
- JLabel username, password;
- JButton bLogin,bClear;
- JPanel pTop;
- JFrame mainFrame;
- public AttendanceGUI() {
- mainFrame = new JFrame();
- mainFrame.setTitle("Student Attendance System");
- mainFrame.setSize(400,150);
- mainFrame.setLocation(100,100);
- mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- pTop = new JPanel();
- pTop.setLayout(new GridLayout(3,2));
- usernameEntry = new JTextField("Student ID");
- passwordEntry = new JTextField("Matric Number");
- username = new JLabel("Username",JLabel.LEFT);
- password = new JLabel("Password",JLabel.LEFT);
- bLogin = new JButton("Login");
- bLogin.addActionListener(new ButtonHandler());
- bClear = new JButton("Clear");
- bClear.addActionListener(new ButtonHandler());
- pTop.add(username);
- pTop.add(usernameEntry);
- pTop.add(password);
- pTop.add(passwordEntry);
- pTop.add(bLogin);
- pTop.add(bClear);
- mainFrame.add(pTop);
- mainFrame.setVisible(true);
- }
- public static void main(String [] args)
- {
- JFrame.setDefaultLookAndFeelDecorated(true);
- AttendanceGUI attendanceSystem = new AttendanceGUI();
- }
- public class ButtonHandler implements ActionListener
- {
- String adminAccount="admin";
- String adminPassword="pass";
- String[] accUserInfo={"1234567A","1234567B","1234567C","1234567D"};
- String[] accPassInfo={"1234567A","1234567B","1234567C","1234567D"};
- Vector<AccountData> testing = new Vector<AccountData>();
- String[] test={"Absent","Absent","Absent","Absent"};
- int i=0;
- public void actionPerformed(ActionEvent evt)
- {
- if(evt.getSource() == bLogin)
- {
- String studentID = usernameEntry.getText();
- String studentPassword = passwordEntry.getText();
- Vector<String> vec = new Vector<String>();
- Date today = new Date();
- loop: for(String x : accUserInfo)
- {
- if (studentID.compareToIgnoreCase(adminAccount) == 0 && studentPassword.compareToIgnoreCase(adminPassword) == 0)
- {
- JOptionPane.showMessageDialog(mainFrame, "Student ID: "+accUserInfo[0]+" Login Date: "+test[0]+
- "\nStudent ID: "+accUserInfo[1]+" Login Date: "+test[1]+
- "\nStudent ID: "+accUserInfo[2]+" Login Date: "+test[2]+
- "\nStudent ID: "+accUserInfo[3]+" Login Date: "+test[3] , "Attendance List", JOptionPane.INFORMATION_MESSAGE);
- break loop;
- }
- else if (studentID.compareToIgnoreCase(x)==0 && studentPassword.compareToIgnoreCase(x)==0)
- {
- test[i]=today.toString();
- testing.add(new AccountData(x, today.toString()));
- JOptionPane.showMessageDialog(mainFrame, "Student ID: "+studentID+" Login Date: "+today.toString() , "Attendance Marked", JOptionPane.INFORMATION_MESSAGE);
- i++;
- if (i>3)
- {
- i=0;
- }
- break loop;
- }
- if (x == accUserInfo[accUserInfo.length-1])
- {
- JOptionPane.showMessageDialog(mainFrame, "Error: Invalid Login Information" , "Login Error", JOptionPane.INFORMATION_MESSAGE);
- }
- }
- }
- if(evt.getSource() == bClear)
- {
- usernameEntry.setText("");
- passwordEntry.setText("");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement