-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginadmin.java
108 lines (89 loc) · 3.95 KB
/
loginadmin.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class loginadmin {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> createAndShowGUI());
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Sign In");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500, 700);
// Background image
ImageIcon backgroundImage = new ImageIcon("loginbackground.png"); // Replace with your image path
JLabel backgroundLabel = new JLabel(backgroundImage);
frame.setContentPane(backgroundLabel);
// Create a JPanel for the sign-in form
JPanel panel = new JPanel(null);
panel.setOpaque(false);
// Username label
JLabel usernameLabel = new JLabel("Username");
usernameLabel.setBounds(1055, 125, 80, 20);
// Username field
JTextField usernameField = new JTextField(20);
usernameField.setBounds(1012, 150, 170, 30);
// Password label
JLabel passwordLabel = new JLabel("Password");
passwordLabel.setBounds(1055, 185, 80, 20);
// Password field
JPasswordField passwordField = new JPasswordField(20);
passwordField.setBounds(1012, 215, 170, 30);
// Login button with icon
ImageIcon loginIcon = new ImageIcon("login.png"); // Replace with your icon image path
JButton loginButton = new JButton("Login", loginIcon);
loginButton.setBounds(995,260, 200, 40);
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Add your login logic here
String username = usernameField.getText();
String password = new String(passwordField.getPassword());
//String roomid = roomid1.getText();
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sys", "root", "password123A$");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM admin WHERE username='" + username + "' AND password='" + password + "'");
if (rs.next()) {
// If there is a match, navigate to the studenthome page
frame.dispose();
adminhome.main(null);
} else {
// If there is no match, display an error message
JOptionPane.showMessageDialog(frame, "Invalid username or password", "Error", JOptionPane.ERROR_MESSAGE);
}
con.close();
} catch (Exception ex) {
System.out.println(ex);
}
}
});
// Register button with icon
ImageIcon registerIcon = new ImageIcon("register.png"); // Replace with your icon image path
JButton registerButton = new JButton("Register", registerIcon);
registerButton.setBounds(995, 315, 200, 40);
registerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Add your registration logic here
}
});
// Add components to the panel
frame.add(usernameLabel);
frame.add(usernameField);
frame.add(passwordLabel);
frame.add(passwordField);
frame.add(loginButton);
frame.add(registerButton);
// Add the panel to the background label
backgroundLabel.add(panel);
frame.setVisible(true);
}
public void setVisible(boolean b) {
}
}