-
Notifications
You must be signed in to change notification settings - Fork 3
/
Login.java
106 lines (86 loc) · 3.38 KB
/
Login.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
package university.management.system;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Login extends JFrame implements ActionListener{
JButton login, cancel;
JTextField tfusername, tfpassword;
Login () {
getContentPane().setBackground(Color.WHITE);
setLayout(null);
JLabel lblusername = new JLabel("Username");
lblusername.setBounds(40, 20, 100, 20);
add(lblusername);
tfusername = new JTextField();
tfusername.setBounds(150, 20, 150, 20);
add(tfusername);
JLabel lblpassword = new JLabel("Password");
lblpassword.setBounds(40, 70, 100, 20);
add(lblpassword);
tfpassword = new JPasswordField();
tfpassword.setBounds(150, 70, 150, 20);
add(tfpassword);
login = new JButton("Login");
login.setBounds(40, 140, 120, 30);
login.setBackground(Color.BLACK);
login.setForeground(Color.WHITE);
login.addActionListener(this);
login.setFont(new Font("Tahoma", Font.BOLD, 15));
add(login);
cancel = new JButton("Cancel");
cancel.setBounds(180, 140, 120, 30);
cancel.setBackground(Color.BLACK);
cancel.setForeground(Color.WHITE);
cancel.addActionListener(this);
cancel.setFont(new Font("Tahoma", Font.BOLD, 15));
add(cancel);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons1/admin1.png"));
// ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/second.jpg"));
Image i2 = i1.getImage().getScaledInstance(225, 225, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
JLabel image = new JLabel(i3);
image.setBackground(Color.cyan);
image.setBounds(330, 10, 225, 225);
add(image);
setSize(600, 300);
setLocation(500, 250);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == login) {
String username = tfusername.getText();
String password = tfpassword.getText();
String query = "select * from login where username='"+username+"' and password='"+password+"'";
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery(query);
if (rs.next()) {
setVisible(false);
new Project();
}
else if (ae.getSource() == login)
{
String username1 = tfusername.getText();
String password1 = tfpassword.getText();
if (username1.equals("hasnat") && password1.equals("1234")){
setVisible(false);
new Project();
}
}
else {
JOptionPane.showMessageDialog(null, "Invalid username or password");
setVisible(false);
}
c.s.close();
} catch (Exception e) {
e.printStackTrace();
}
} else if (ae.getSource() == cancel) {
setVisible(false);
}
}
public static void main(String[] args) {
new Login();
}
}