-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI2.java
More file actions
61 lines (53 loc) · 2.07 KB
/
GUI2.java
File metadata and controls
61 lines (53 loc) · 2.07 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class GUI2 {
public static void NewScreen()
{
JFrame f=new JFrame ("Admin Login");
JLabel namelabel = new JLabel("Name:");
namelabel.setBounds(20,30,150,10);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(13,50,150,10);
JTextField userText =new JTextField();
userText.setBounds(80,20,200,20);
JPasswordField passwordText= new JPasswordField();
passwordText.setBounds(80,50,200,20);
JButton jb1 = new JButton("Login");
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String userName = userText.getText();
String password = passwordText.getText();
try {
Connection connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/admin",
"root", "root123");
PreparedStatement st = (PreparedStatement) connection
.prepareStatement("Select aname, passcode from authentication where aname=? and passcode=?");
st.setString(1, userName);
st.setString(2, password);
ResultSet rs = st.executeQuery();
if (rs.next()) {
f.dispose();
GUI3 ah = new GUI3();
ah.Screen();
JOptionPane.showMessageDialog(jb1, "You have successfully logged in");
} else {
JOptionPane.showMessageDialog(jb1, "Wrong Username & Password");
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
}
}
});
jb1.setBounds(100,100,100, 50);
f.add(namelabel);
f.add(passwordLabel);
f.add(userText);
f.add(passwordText);
f.add(jb1);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}