-
Notifications
You must be signed in to change notification settings - Fork 3
/
StudentLogin.java
78 lines (67 loc) · 2.46 KB
/
StudentLogin.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
package university.management.system;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class StudentLogin extends JFrame implements ActionListener {
JTextField rollnoField, emailField;
JButton login, back;
StudentLogin() {
setLayout(null);
getContentPane().setBackground(Color.WHITE);
JLabel rollnoLabel = new JLabel("Roll Number");
rollnoLabel.setBounds(40, 20, 100, 30);
add(rollnoLabel);
rollnoField = new JTextField();
rollnoField.setBounds(150, 20, 150, 30);
add(rollnoField);
JLabel emailLabel = new JLabel("Email");
emailLabel.setBounds(40, 70, 100, 30);
add(emailLabel);
emailField = new JTextField();
emailField.setBounds(150, 70, 150, 30);
add(emailField);
login = new JButton("Login");
login.setBackground(Color.BLACK);
login.setForeground(Color.WHITE);
login.setBounds(40, 140, 120, 30);
login.addActionListener(this);
add(login);
back = new JButton("Back");
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
back.setBounds(180, 140, 120, 30);
back.addActionListener(this);
add(back);
setSize(600, 300);
setLocation(400, 200);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == login) {
String rollno = rollnoField.getText();
String email = emailField.getText();
String query = "select * from student where rollno = '" + rollno + "' and email = '" + email + "'";
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery(query);
if (rs.next()) {
new StudentDetails().setVisible(true);
this.setVisible(false);
} else {
JOptionPane.showMessageDialog(null, "Invalid Login");
rollnoField.setText("");
emailField.setText("");
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (ae.getSource() == back) {
new Project().setVisible(true);
this.setVisible(false);
}
}
public static void main(String[] args) {
new StudentLogin();
}
}