Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 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. String[] accUserInfo={"1234567A","1234567B","1234567C","1234567D"};
  68. String[] accPassInfo={"1234567A","1234567B","1234567C","1234567D"};
  69. Vector<AccountData> testing = new Vector<AccountData>();
  70. String[] test={"Absent","Absent","Absent","Absent"};
  71. int i=0;
  72.  
  73. public void actionPerformed(ActionEvent evt)
  74. {
  75. if(evt.getSource() == bLogin)
  76. {
  77. String studentID = usernameEntry.getText();
  78. String studentPassword = passwordEntry.getText();
  79. Vector<String> vec = new Vector<String>();
  80. Date today = new Date();
  81. loop: for(String x : accUserInfo)
  82. {
  83. if (studentID.compareToIgnoreCase(adminAccount) == 0 && studentPassword.compareToIgnoreCase(adminPassword) == 0)
  84. {
  85. JOptionPane.showMessageDialog(mainFrame, "Student ID: "+accUserInfo[0]+" Login Date: "+test[0]+
  86. "\nStudent ID: "+accUserInfo[1]+" Login Date: "+test[1]+
  87. "\nStudent ID: "+accUserInfo[2]+" Login Date: "+test[2]+
  88. "\nStudent ID: "+accUserInfo[3]+" Login Date: "+test[3] , "Attendance List", JOptionPane.INFORMATION_MESSAGE);
  89. break loop;
  90. }
  91. else if (studentID.compareToIgnoreCase(x)==0 && studentPassword.compareToIgnoreCase(x)==0)
  92. {
  93. test[i]=today.toString();
  94. testing.add(new AccountData(x, today.toString()));
  95. JOptionPane.showMessageDialog(mainFrame, "Student ID: "+studentID+" Login Date: "+today.toString() , "Attendance Marked", JOptionPane.INFORMATION_MESSAGE);
  96. i++;
  97. if (i>3)
  98. {
  99. i=0;
  100. }
  101. break loop;
  102. }
  103. if (x == accUserInfo[accUserInfo.length-1])
  104. {
  105. JOptionPane.showMessageDialog(mainFrame, "Error: Invalid Login Information" , "Login Error", JOptionPane.INFORMATION_MESSAGE);
  106. }
  107. }
  108. }
  109. if(evt.getSource() == bClear)
  110. {
  111. usernameEntry.setText("");
  112. passwordEntry.setText("");
  113. }
  114.  
  115. }
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement