-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhomePage.java
154 lines (137 loc) · 4.63 KB
/
homePage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package regPrototype;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import javax.swing.DropMode;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPasswordField;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.HashSet;
public class homePage extends JFrame {
private static int loginStatus = 0;
private JPanel contentPane;
private JTextField textUserName;
private JPasswordField textPassword;
private static Database userDatabase = new Database();
private static User currentUser= null;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
homePage frame = new homePage();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static void setCurrentUser(User login){
currentUser= login;
}
public static User getCurrentUser(){
return currentUser;
}
public static Database getDatabase(){
return userDatabase;
}
private class loginButtonListener implements ActionListener{
public void actionPerformed (ActionEvent e){
userDatabase.allRegistrars.add(new Registrar("Cristian", "Ayub", "cayub", "asdf1",userDatabase.allRegistrars));
userDatabase.allProfessors.add(new Professor("Jesus", "Juarez", "jjuarez", "asdf2","Computer Science", userDatabase.allProfessors));
userDatabase.allStudents.add(new Student("Gabriel", "Felix", "gmfelix", "asdf3", userDatabase.allStudents));
userDatabase.allStudents.add(new Student("Hugo", "Ocon", "hocon", "ho123", userDatabase.allStudents));
String user = textUserName.getText();
String pass = textPassword.getText();
user = user.toLowerCase();
loginStatus = User.login(userDatabase, user, pass);
//Validate user
if(loginStatus == 3){
dispose();
new registrarHome().setVisible(true);
} else if(loginStatus == 1){
dispose();
new studentHome().setVisible(true);
} else if(loginStatus == 2){
dispose();
new professorHome().setVisible(true);
} else{
JOptionPane.showMessageDialog(null, "Error: Wrong user name or password.");
}
}
}
private class resetButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
textUserName.setText("");
textPassword.setText("");
}
}
/**
* Create the frame.
*/
public homePage() {
setTitle("Home Page");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(new Color(0, 102, 153));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnLogIn = new JButton("Log in");
btnLogIn.setBounds(116, 208, 89, 23);
contentPane.add(btnLogIn);
btnLogIn.addActionListener(new loginButtonListener());
textUserName = new JTextField();
textUserName.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
textUserName.setText("");
}
});
textUserName.setText("Enter username here...");
textUserName.setBounds(133, 86, 170, 20);
contentPane.add(textUserName);
textUserName.setColumns(10);
JLabel lblUserName = new JLabel("Username");
lblUserName.setForeground(new Color(255, 255, 255));
lblUserName.setBounds(133, 52, 170, 23);
contentPane.add(lblUserName);
JLabel lblPassword = new JLabel("Password");
lblPassword.setForeground(new Color(255, 255, 255));
lblPassword.setBounds(133, 124, 170, 23);
contentPane.add(lblPassword);
textPassword = new JPasswordField();
textPassword.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER)
textPassword.addActionListener(new loginButtonListener());
}
});
textPassword.setToolTipText("");
textPassword.setBounds(133, 158, 170, 20);
contentPane.add(textPassword);
textPassword.setColumns(10);
JButton btnReset = new JButton("Reset");
btnReset.setBounds(241, 208, 89, 23);
contentPane.add(btnReset);
btnReset.addActionListener(new resetButtonListener());
}
}