-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHRMenu.java
More file actions
132 lines (107 loc) · 3.15 KB
/
Copy pathHRMenu.java
File metadata and controls
132 lines (107 loc) · 3.15 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.sql.*;
import javax.swing.JPasswordField;
public class HRMenu extends JFrame {
private JPanel contentPane;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HRMenu frame = new HRMenu();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/*BEGINNING of SQL CODE
*/
Connection connection = null; //Connection -------------------------------------------------------------------------
private JPasswordField passwordField_1;
/**
* Create the frame.
*/
public HRMenu() {
setTitle("Login");
connection=db.dbConnector(); //Method in db class ---------------------------------------------------------------
/*END of SQL CODE
*/
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(178, 41, 116, 28);
contentPane.add(textField);
textField.setColumns(10);
JLabel lblPassword = new JLabel("Password");
lblPassword.setBounds(85, 111, 62, 14);
contentPane.add(lblPassword);
JLabel lblUsername = new JLabel("Username");
lblUsername.setBounds(85, 50, 62, 14);
contentPane.add(lblUsername);
JButton btnSubmit = new JButton("Login");
btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try
{
String query = "SELECT * FROM admin WHERE Username=? AND Password=?";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1,textField.getText());
ps.setString(2,passwordField_1.getText()); //deprecated but works
ResultSet rs = ps.executeQuery();
int count = 0;
while(rs.next())
{
count+=1;
}
if (count == 1)
{
JOptionPane.showMessageDialog(null, "Username & Password is Correct!");
HRMainMenu mainmenu = new HRMainMenu();
setVisible(false);
mainmenu.setVisible(true);
}
else if (count > 1)
{
JOptionPane.showMessageDialog(null, "Duplicate Username & Password");
}
else
{
JOptionPane.showMessageDialog(null, "Username & Password is Incorrect! Try Again");
textField.setText("");
passwordField_1.setText("");
}
rs.close();
ps.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
});
btnSubmit.setBounds(249, 197, 89, 23);
contentPane.add(btnSubmit);
passwordField_1 = new JPasswordField();
passwordField_1.setBounds(178, 105, 116, 26);
contentPane.add(passwordField_1);
}
}