This repository was archived by the owner on Jul 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistration.java
More file actions
173 lines (148 loc) · 5.61 KB
/
Copy pathRegistration.java
File metadata and controls
173 lines (148 loc) · 5.61 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
// package tec181;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPasswordField;
public class Registration extends JFrame {
private JPanel contentPane;
private JTextField fNameField;
private JTextField lNameField;
private JTextField unField;
private JPasswordField pwdField;
public Registration() {
Connection conn = Database.dbConnect();
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 455, 440);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JLayeredPane layeredPane = new JLayeredPane();
contentPane.add(layeredPane, BorderLayout.CENTER);
JLabel signUpTitle = new JLabel("Create New Account");
signUpTitle.setBounds(0, 11, 429, 80);
layeredPane.add(signUpTitle);
signUpTitle.setFont(new Font("Simplex", Font.BOLD, 30));
signUpTitle.setHorizontalAlignment(SwingConstants.CENTER);
fNameField = new JTextField();
fNameField.setBounds(221, 102, 114, 20);
layeredPane.add(fNameField);
fNameField.setColumns(10);
JLabel fName = new JLabel("First Name");
fName.setFont(new Font("Segoe UI Symbol", Font.PLAIN, 13));
fName.setBounds(60, 102, 86, 25);
layeredPane.add(fName);
lNameField = new JTextField();
lNameField.setBounds(221, 133, 114, 20);
layeredPane.add(lNameField);
lNameField.setColumns(10);
JLabel lName = new JLabel("Last Name");
lName.setFont(new Font("Segoe UI Symbol", Font.PLAIN, 13));
lName.setBounds(60, 139, 86, 14);
layeredPane.add(lName);
unField = new JTextField();
unField.setBounds(220, 164, 115, 20);
layeredPane.add(unField);
unField.setColumns(10);
JLabel userName = new JLabel("Username");
userName.setFont(new Font("Segoe UI Symbol", Font.PLAIN, 13));
userName.setBounds(60, 170, 86, 14);
layeredPane.add(userName);
pwdField = new JPasswordField();
pwdField.setBounds(221, 196, 114, 20);
layeredPane.add(pwdField);
JLabel pwd = new JLabel("Password");
pwd.setFont(new Font("Segoe UI Symbol", Font.PLAIN, 13));
pwd.setBounds(60, 202, 86, 14);
layeredPane.add(pwd);
JButton signUpButton = new JButton("Sign up");
signUpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if(unField.getText().length() == 0 || String.valueOf(pwdField.getPassword()).length() == 0) {
JOptionPane.showMessageDialog(null, "Username or Password can not be empty.", "Username and Password is empty", JOptionPane.WARNING_MESSAGE);
} else {
PreparedStatement pst = conn.prepareStatement("SELECT userName FROM `signup` WHERE userName=?");
pst.setString(1, unField.getText());
ResultSet rs = pst.executeQuery();
if(rs.next()) {
JOptionPane.showMessageDialog(null, unField.getText() + " username already taken. Please try with different username.", "Username taken already", JOptionPane.WARNING_MESSAGE);
unField.setText("");
} else {
pst = conn.prepareStatement("INSERT INTO `signup`(fName, lName, userName, pwd) VALUES(?, ?, ?, ?)");
pst.setString(1, fNameField.getText());
pst.setString(2, lNameField.getText());
pst.setString(3, unField.getText());
pst.setString(4, String.valueOf(pwdField.getPassword()));
pst.executeUpdate();
fNameField.setText("");
lNameField.setText("");
unField.setText("");
pwdField.setText("");
JOptionPane.showMessageDialog(null, "Sing up Successful. Welcome to Student Portal", "Welcome to Portal", JOptionPane.INFORMATION_MESSAGE);
try {
Student frame = new Student();
frame.setVisible(true);
dispose();
} catch (Exception e1) {
e1.printStackTrace();
}
}
pst.close();
rs.close();
}
} catch(SQLException e1) {
e1.printStackTrace();
}
}
});
signUpButton.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 13));
signUpButton.setBounds(162, 255, 89, 23);
layeredPane.add(signUpButton);
JButton loginButton = new JButton("Login");
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e1) {
e1.printStackTrace();
}
dispose();
}
});
loginButton.setBounds(162, 305, 89, 23);
loginButton.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 13));
layeredPane.add(loginButton);
JButton homeButton = new JButton("Home");
homeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
MainWindow frame = new MainWindow();
frame.setVisible(true);
dispose();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
homeButton.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 13));
homeButton.setBounds(162, 354, 89, 23);
layeredPane.add(homeButton);
}
}