-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistrationForm.java
More file actions
265 lines (200 loc) · 8 KB
/
Copy pathRegistrationForm.java
File metadata and controls
265 lines (200 loc) · 8 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package campusComplaints;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
public class RegistrationForm extends JFrame implements ActionListener {
JTextField nameField,emailField, mobileField;
JPasswordField passField,confirmPassField;
JButton otpBtn,clearBtn,eyeBtn1,eyeBtn2;
ImageIcon eyeOpenIcon,eyeCloseIcon;
char passEcho,confirmEcho;
Connection conn;
Statement stmt;
ResultSet rs;
public RegistrationForm() {
setTitle("Registration Form");
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
ImageIcon bgIcon = new ImageIcon(
RegistrationForm.class.getResource("centralplaza.jpg"));
Image img = bgIcon.getImage();
Image scaledImg = img.getScaledInstance(
screenSize.width,
screenSize.height,
Image.SCALE_SMOOTH);
ImageIcon scaledIcon = new ImageIcon(scaledImg);
JLabel background = new JLabel(scaledIcon);
background.setBounds(0, 0, screenSize.width, screenSize.height);
add(background);
JPanel panel1 = new JPanel();
panel1.setLayout(null);
panel1.setBackground(Color.WHITE);
panel1.setBounds(0, 0, screenSize.width, 75);
background.add(panel1);
JLabel heading = new JLabel("LNMIIT BUS SERVICES");
heading.setFont(new Font("Arial", Font.BOLD, 28));
heading.setForeground(Color.BLACK);
heading.setBounds(600, 15, 500, 40);
panel1.add(heading);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBackground(Color.WHITE);
panel.setBounds(500, 150, 500, 500);
background.add(panel);
JLabel title = new JLabel("Welcome, New User 👋");
title.setFont(new Font("Segoe UI Emoji", Font.BOLD, 24));
title.setBounds(120, 20, 300, 30);
panel.add(title);
JLabel nameLabel = new JLabel("Name:");
nameLabel.setBounds(80, 80, 100, 25);
panel.add(nameLabel);
nameField = new JTextField();
nameField.setBounds(200, 80, 200, 25);
panel.add(nameField);
JLabel emailLabel = new JLabel("Roll number:");
emailLabel.setBounds(80, 130, 100, 25);
panel.add(emailLabel);
emailField = new JTextField();
emailField.setBounds(200, 130, 200, 25);
panel.add(emailField);
JLabel mobileLabel = new JLabel("Mobile No:");
mobileLabel.setBounds(80, 180, 100, 25);
panel.add(mobileLabel);
mobileField = new JTextField();
mobileField.setBounds(200, 180, 200, 25);
panel.add(mobileField);
JLabel passLabel = new JLabel("Create Password:");
passLabel.setBounds(80, 230, 100, 25);
panel.add(passLabel);
passField = new JPasswordField();
passField.setBounds(200, 230, 200, 25);
panel.add(passField);
JLabel confirmPassLabel = new JLabel("Confirm Password:");
confirmPassLabel.setBounds(80, 280, 150, 25);
panel.add(confirmPassLabel);
confirmPassField = new JPasswordField();
confirmPassField.setBounds(200, 280, 200, 25);
panel.add(confirmPassField);
otpBtn = new JButton("Register");
otpBtn.setBounds(90, 340, 140, 35);
panel.add(otpBtn);
clearBtn = new JButton("Clear");
clearBtn.setBounds(270, 340, 140, 35);
panel.add(clearBtn);
Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
otpBtn.setCursor(cursor);
clearBtn.setCursor(cursor);
otpBtn.setBackground(Color.WHITE);
otpBtn.setForeground(Color.BLACK);
otpBtn.setOpaque(true);
otpBtn.setContentAreaFilled(true);
otpBtn.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseEntered(java.awt.event.MouseEvent e) {
otpBtn.setBackground(Color.BLUE);
otpBtn.setForeground(Color.WHITE);
}
@Override
public void mouseExited(java.awt.event.MouseEvent e) {
otpBtn.setBackground(Color.WHITE);
otpBtn.setForeground(Color.BLACK);
}
});
clearBtn.setBackground(Color.LIGHT_GRAY);
clearBtn.setForeground(Color.BLACK);
clearBtn.addActionListener(this);
eyeOpenIcon = new ImageIcon(getClass().getResource("eye_open.png"));
eyeCloseIcon = new ImageIcon(getClass().getResource("eye_closed.png"));
passEcho = passField.getEchoChar();
confirmEcho = confirmPassField.getEchoChar();
eyeBtn1 = new JButton(eyeOpenIcon);
eyeBtn1.setBounds(400, 230, 35, 25);
eyeBtn1.setBorderPainted(false);
eyeBtn1.setFocusPainted(false);
eyeBtn1.setContentAreaFilled(false);
eyeBtn1.addActionListener(this);
panel.add(eyeBtn1);
eyeBtn2 = new JButton(eyeOpenIcon);
eyeBtn2.setBounds(400, 280, 35, 25);
eyeBtn2.setBorderPainted(false);
eyeBtn2.setFocusPainted(false);
eyeBtn2.setContentAreaFilled(false);
eyeBtn2.addActionListener(this);
panel.add(eyeBtn2);
eyeBtn1.setCursor(cursor);
eyeBtn2.setCursor(cursor);
otpBtn.addActionListener(this);
setVisible(true);
connectDB();
}
// Database connection method
private void connectDB()
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/BusManagement","root","Root@1234");
System.out.println("Database Connected.");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, "Database Connection Failed: " + e.getMessage());
}
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == eyeBtn1) {
if (passField.getEchoChar() == 0) {
passField.setEchoChar(passEcho);
eyeBtn1.setIcon(eyeOpenIcon);
} else {
passField.setEchoChar((char) 0);
eyeBtn1.setIcon(eyeCloseIcon);
}
}
else if (e.getSource() == eyeBtn2) {
if (confirmPassField.getEchoChar() == 0) {
confirmPassField.setEchoChar(confirmEcho);
eyeBtn2.setIcon(eyeOpenIcon);
} else {
confirmPassField.setEchoChar((char) 0);
eyeBtn2.setIcon(eyeCloseIcon);
}
}
else if (e.getSource()==otpBtn) {
String name = nameField.getText();
String roll = emailField.getText();
String mobile = mobileField.getText();
String password = String.valueOf(passField.getPassword());
try {
String query = "INSERT INTO Student (Name, RollNumber , mobile, password) VALUES (?, ?, ?, ?)";
PreparedStatement pst = conn.prepareStatement(query);
pst.setString(1, name);
pst.setString(2, roll);
pst.setString(3, mobile);
pst.setString(4, password);
pst.executeUpdate();
JOptionPane.showMessageDialog(this, "Student Registered Successfully ✅");
clearFields();
}
catch (SQLException e1) {
JOptionPane.showMessageDialog(this, "Error: " + e1.getMessage());
}
}
else if (e.getSource()==clearBtn) {
clearFields();
}
}
private void clearFields() {
nameField.setText("");
emailField.setText("");
mobileField.setText("");
passField.setText("");
confirmPassField.setText("");
}
public static void main(String[] args) {
new RegistrationForm();
}
}