Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. /**
  2.  * Student Attendance System
  3.  * Object Oriented Programming
  4.  * P03
  5.  * Nicholas Leong
  6.  * 1002827B
  7.  */
  8.  
  9. //Import required GUI files
  10. import java.util.*;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. import javax.swing.*;
  14. import java.util.Vector;
  15.  
  16. public class AttendanceGUI {
  17.  
  18.     JTextField usernameEntry, passwordEntry;
  19.     JLabel username, password;
  20.     JButton bLogin,bClear;
  21.     JPanel pTop;
  22.     JFrame mainFrame;
  23.  
  24.     public AttendanceGUI() {
  25.  
  26.             mainFrame = new JFrame();
  27.             mainFrame.setTitle("Student Attendance System");
  28.             mainFrame.setSize(400,150);
  29.             mainFrame.setLocation(100,100);
  30.             mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.  
  32.             pTop = new JPanel();
  33.             pTop.setLayout(new GridLayout(3,2));
  34.  
  35.             usernameEntry = new JTextField("Student ID");
  36.             passwordEntry = new JTextField("Matric Number");
  37.             username = new JLabel("Username",JLabel.LEFT);
  38.             password = new JLabel("Password",JLabel.LEFT);
  39.  
  40.             bLogin = new JButton("Login");
  41.             bLogin.addActionListener(new ButtonHandler());
  42.  
  43.             bClear = new JButton("Clear");
  44.             bClear.addActionListener(new ButtonHandler());
  45.  
  46.             pTop.add(username);
  47.             pTop.add(usernameEntry);
  48.             pTop.add(password);
  49.             pTop.add(passwordEntry);
  50.             pTop.add(bLogin);
  51.             pTop.add(bClear);
  52.  
  53.             mainFrame.add(pTop);
  54.             mainFrame.setVisible(true);
  55.     }
  56.  
  57.     public static void main(String [] args)
  58.     {
  59.         JFrame.setDefaultLookAndFeelDecorated(true);
  60.         AttendanceGUI attendanceSystem = new AttendanceGUI();
  61.     }
  62.  
  63.     public class ButtonHandler implements ActionListener
  64.     {
  65.     String adminAccount="admin";
  66.     String adminPassword="pass";
  67.     Vector<AccountData> testing = new Vector<AccountData>();
  68.     testing.add(new AccountData("1234567A","1234567A"));
  69.     testing.add(new AccountData("1234567B","1234567B"));
  70.     testing.add(new AccountData("1234567C","1234567C"));
  71.     testing.add(new AccountData("1234567D","1234567D"));
  72.     int i=0;
  73.  
  74.         public void actionPerformed(ActionEvent evt)
  75.         {
  76.                 if(evt.getSource() == bLogin)
  77.                 {
  78.                 String studentID = usernameEntry.getText();
  79.                 String studentPassword = passwordEntry.getText();
  80.                 Vector<String> vec = new Vector<String>();
  81.                 Date today = new Date();
  82.                 loop: for(AccountData d: testing)
  83.                 {
  84.                     if (studentID.compareToIgnoreCase(adminAccount) == 0 && studentPassword.compareToIgnoreCase(adminPassword) == 0)
  85.                     {
  86.                         loop2: for(AccountData e: testing)
  87.                         {
  88.                             make a long string with your message here
  89.                         }
  90.                         JOptionPane.showMessageDialog(mainFrame, thatLongStringYouDidInTheLoop2 , "Attendance List", JOptionPane.INFORMATION_MESSAGE);
  91.                         break loop;
  92.                     }
  93.                     else if (studentID.compareToIgnoreCase(d.getStudentID())==0 && studentPassword.compareToIgnoreCase(d.getStudentID())==0)
  94.                     {
  95.                         test[i]=today.toString();
  96.                         d.setAttendance(today.toString());
  97.                         JOptionPane.showMessageDialog(mainFrame, "Student ID: "+d.getStudentID()+" Login Date: "+today.toString() , "Attendance Marked", JOptionPane.INFORMATION_MESSAGE);
  98.                         break loop;
  99.                     }
  100.                     if (x == accUserInfo[accUserInfo.length-1])
  101.                     {
  102.                     JOptionPane.showMessageDialog(mainFrame, "Error: Invalid Login Information" , "Login Error", JOptionPane.INFORMATION_MESSAGE);
  103.                     }
  104.                 }
  105.                 }
  106.                 if(evt.getSource() == bClear)
  107.                 {
  108.                     usernameEntry.setText("");
  109.                     passwordEntry.setText("");
  110.                 }
  111.  
  112.             }
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement