-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyFrame.java
More file actions
77 lines (73 loc) · 2.91 KB
/
Copy pathMyFrame.java
File metadata and controls
77 lines (73 loc) · 2.91 KB
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
package org.Miniproject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class MyFrame extends JFrame implements ActionListener {
MyPanel p1,p2;
MyFrame() {
p1 = new MyPanel("Log-In");
p1.jb1.addActionListener(this);
p1.jb2.addActionListener(this);
p1.jb5.addActionListener(this);
this.getContentPane().setLayout(new GridBagLayout());
this.getContentPane().add(p1);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setUndecorated(true);
this.setAlwaysOnTop(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.getRootPane().setDefaultButton(p1.jb1);
}
@Override
public void actionPerformed(ActionEvent ae){
String cmd = ae.getActionCommand();
if("login_submit".equals(cmd)) {
String Username = p1.tf1.getText().trim();
String USN = p1.tf2.getText().toUpperCase();
String Subcode = (String) p1.cb1.getSelectedItem();
if(ValueCheck(USN,Username)) {
MyPanel.createDialog(this,Username,USN,Subcode); //loads the dialog
}
else
JOptionPane.showMessageDialog(this,"Invalid input");
}
else if("Sync".equals(cmd)) {
ConfigSyncManager.resetSyncFlag();
ConfigSyncManager.syncOnce();
p1.refreshSubjects();
}
else if("admin_panel".equals(cmd)) { //changes panel to admin login
this.getContentPane().remove(p1);
p2 = new MyPanel();
p2.jb3.addActionListener(this);
p2.jb4.addActionListener(this);
this.getContentPane().add(p2);
this.revalidate();
this.repaint();
this.getRootPane().setDefaultButton(p2.jb3);
}
else if("admin_submit".equals(cmd)) {
String password = new String(p2.tf3.getPassword());
if (password.equals(ConfigLoader.getProperty("ADMIN_PASSWORD"))) //checks for admin password
System.exit(0);
else
JOptionPane.showMessageDialog(this, "Wrong password");
}
else if("back".equals(cmd)) {
this.getContentPane().remove(p2);
this.getContentPane().add(p1);
this.revalidate();
this.repaint();
this.getRootPane().setDefaultButton(p1.jb1);
}
}
protected boolean ValueCheck(String usn,String name) {
if(usn.isEmpty() || name.isEmpty() || usn.length() != 10)
return false;
String pattern = "^1[A-Z]{2}\\d{2}[A-Z]{2}\\d{3}$"; //regex only for 10-digit USN (vtu pattern)
return usn.matches(pattern);
}
}