-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI5.java
More file actions
60 lines (53 loc) · 2.13 KB
/
GUI5.java
File metadata and controls
60 lines (53 loc) · 2.13 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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class GUI5 {
public static void Screen5()
{
JFrame f=new JFrame ("Accountant 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/accountant",
"root", "root123");
PreparedStatement st = (PreparedStatement) connection
.prepareStatement("Select firstname, password from account where firstname=? and password=?");
st.setString(1, userName);
st.setString(2, password);
ResultSet rs = st.executeQuery();
if (rs.next()) {
f.dispose();
GUI6 ob = new GUI6();
ob.Screen6();
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);
}
}