-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewUser.java
More file actions
216 lines (207 loc) · 5.2 KB
/
Copy pathNewUser.java
File metadata and controls
216 lines (207 loc) · 5.2 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
import javax.swing.*;
import java.awt.Color;
import java.awt.event.*;
import java.awt.Font;
import javax.swing.JOptionPane;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.logging.Level;
import java.util.logging.Logger;
public class NewUser extends JFrame implements ActionListener
{
JPanel p1,p2;
JLabel l1,l2,l3,l4,l5,l6,l7;
JTextField t1,t2,t3,t4,t5;
JPasswordField pass;
JComboBox<String> user;
JCheckBox show;
JButton b1,b2;
Connection con;
NewUser()
{
MyConnection my = new MyConnection();
con = my.Connect();
setTitle("New Registration");
p1 = new JPanel();
p1.setLayout(null);
p1.setBackground(Color.gray);
p1.setBounds(0,0,510,50);
p2 = new JPanel();
p2.setLayout(null);
p2.setBackground(Color.white);
p2.setBounds(0,52,510,500);
l1 = new JLabel("New User Registration");
l1.setFont(new Font("arial",Font.BOLD,18));
l1.setForeground(Color.white);
l1.setBounds(170,15,220,30);
l2 = new JLabel("User Type:");
l2.setFont(new Font("arial",Font.BOLD,14));
l2.setBounds(15,85,145,30);
user = new JComboBox<>();
user.addItem("---Select User---");
user.addItem("Admin");
user.addItem("User");
user.addItem("Trainer");
user.setBounds(130,85,200,30);
l3 = new JLabel("Name:");
l3.setFont(new Font("arial",Font.BOLD,14));
l3.setBounds(15,125,145,30);
t1 = new JTextField();
t1.setBounds(130,125,200,30);
l4 = new JLabel("Mobile No.:");
l4.setFont(new Font("arial",Font.BOLD,14));
l4.setBounds(15,165,145,30);
t2 = new JTextField();
t2.setBounds(130,165,200,30);
l5 = new JLabel("Gmail:");
l5.setFont(new Font("arial",Font.BOLD,14));
l5.setBounds(15,205,145,30);
t3 = new JTextField();
t3.setBounds(130,205,200,30);
l6 = new JLabel("Username:");
l6.setFont(new Font("arial",Font.BOLD,14));
l6.setBounds(15,245,145,30);
t4 = new JTextField();
t4.setBounds(130,245,200,30);
l7 = new JLabel("Password:");
l7.setFont(new Font("arial",Font.BOLD,14));
l7.setBounds(15,285,145,30);
pass = new JPasswordField();
pass.setBounds(130,285,200,30);
show = new JCheckBox("Show Password");
show.setBounds(335,285,130,30);
show.addActionListener(this);
b1 = new JButton("Sign Up");
b1.setBounds(130,320,80,30);
b1.addActionListener(this);
b2 = new JButton("Login");
b2.setBounds(220,320,80,30);
b2.addActionListener(this);
add(p1);
add(p2);
p1.add(l1);
p2.add(l2);
p2.add(user);
p2.add(l3);
p2.add(t1);
p2.add(l4);
p2.add(t2);
p2.add(l5);
p2.add(t3);
p2.add(l6);
p2.add(t4);
p2.add(l7);
p2.add(pass);
p2.add(show);
p2.add(b1);
p2.add(b2);
setSize(510,600);
setLayout(null);
setVisible(true);
setLocationRelativeTo(null);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
String User = user.getSelectedItem().toString();
String name = t1.getText();
String mobile = t2.getText();
String g = t3.getText();
String uname = t4.getText();
String passw = String.valueOf(pass.getPassword());
if(User.equals(""))
{
JOptionPane.showMessageDialog(null,"Select the user type");
}
if(name.equals(""))
{
JOptionPane.showMessageDialog(null,"Add a name");
}
if(mobile.equals(""))
{
JOptionPane.showMessageDialog(null,"Add a Mobile No.");
}
if(g.equals(""))
{
JOptionPane.showMessageDialog(null,"Add a Mail ID");
}
if(uname.equals(""))
{
JOptionPane.showMessageDialog(null,"Add a Username");
}
if(passw.equals(""))
{
JOptionPane.showMessageDialog(null,"Add a Password");
}
if(checkUsername(uname))
{
JOptionPane.showMessageDialog(null,"Username already exists!!");
}
else
{
PreparedStatement st;
String query = "insert into users (USER,NAME,MOBILENO,GMAIL,USERNAME,PASSWORD) values(?,?,?,?,?,?)";
try
{
st = con.prepareStatement(query);
st.setString(1,User);
st.setString(2,name);
st.setString(3,mobile);
st.setString(4,g);
st.setString(5,uname);
st.setString(6,passw);
if(st.executeUpdate() > 0)
{
JOptionPane.showMessageDialog(null,"New User Added");
this.dispose();
}
} catch(SQLException ex)
{
Logger.getLogger(NewUser.class.getName()).log(Level.SEVERE,null,ex);
}
}
}
else if(e.getSource()==b2)
{
this.dispose();
new Login().setVisible(true);
}
else if(show.isSelected())
{
pass.setEchoChar((char)0);
}
else
{
pass.setEchoChar('*');
}
}
public boolean checkUsername(String t4)
{
PreparedStatement st;
ResultSet rs;
boolean checkUsername = false;
String query1 = "SELECT * FROM USERS WHERE USERNAME=?";
try
{
st = con.prepareStatement(query1);
st.setString(1,t4);
rs = st.executeQuery();
if(rs.next())
{
checkUsername = true;
}
} catch(SQLException ex)
{
Logger.getLogger(NewUser.class.getName()).log(Level.SEVERE,null,ex);
}
return checkUsername;
}
public static void main(String[] args)
{
new NewUser();
}
}