-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin.java
More file actions
169 lines (142 loc) · 3.82 KB
/
Copy pathAdmin.java
File metadata and controls
169 lines (142 loc) · 3.82 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Admin extends JFrame {
private JPanel contentPane;
private JTextField userText;
private JPasswordField passText;
ExamData db;
Connection cn;
Statement st;
String sql,examName,ans4;
ResultSet rs;
JButton loginBtn;
private JLabel passlbl;
private JButton homeBtn;
public static void main(String[] args) {
Admin frame = new Admin();
frame.setVisible(true);
}
public Admin() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 344, 258);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel main = new JPanel();
main.setBounds(4, 3, 328, 215);
contentPane.add(main);
main.setLayout(null);
JLabel mainlbl = new JLabel("Admin");
mainlbl.setBounds(6, 5, 65, 25);
main.add(mainlbl);
JLabel userlbl = new JLabel("User");
userlbl.setBounds(6, 56, 46, 25);
main.add(userlbl);
userText = new JTextField();
userText.setBounds(77, 58, 86, 20);
main.add(userText);
userText.setColumns(10);
//userlbl.setLabel()
loginBtn = new JButton("Login");
loginBtn.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER)
{
login();
}
}
});
loginBtn.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.out.println("click");
login();
}
});
loginBtn.setBounds(39, 161, 89, 23);
main.add(loginBtn);
passlbl = new JLabel("Password");
passlbl.setBounds(6, 92, 65, 25);
main.add(passlbl);
passText = new JPasswordField();
passText.setBounds(78, 92, 86, 20);
passText.setEchoChar('*');
main.add(passText);
passText.setColumns(10);
homeBtn = new JButton("Home");
homeBtn.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER)
{
new Home().setVisible(true);
kill();
}
}
});
homeBtn.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
new Home().setVisible(true);
kill();
}
});
homeBtn.setBounds(229, 6, 89, 23);
main.add(homeBtn);
fload();
}
public void fload()
{
try
{
db=new ExamData();
cn=db.getConnection();
st = cn.createStatement();
}
catch (Exception ex)
{
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
public void login()
{
try
{
sql="select * from user1 where username='"+userText.getText()+"' and pass='"+passText.getText()+"'";
System.out.println(sql);
rs=st.executeQuery(sql);
if(rs.next())
{
System.out.println("Login success");
JOptionPane.showMessageDialog(null,"Login success..");
new SetupExam().setVisible(true);
kill();
}
else
{
System.out.println("retry");
JOptionPane.showMessageDialog(null,"User name or password is wrong...!");
}
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null,"User name or password is wrong...!");
}
}
public void kill()
{
this.dispose();
}
}