-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSignup.java
219 lines (182 loc) · 5.75 KB
/
Signup.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
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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import static javax.swing.JOptionPane.showMessageDialog;
public class Signup implements ActionListener{
JFrame frm;
JLabel label1,label2,label3,label4,label5,header,imgLabel1,label6,lab7;
JTextField tf1,tf2,tf3,tf4,tf5;
JPasswordField jp1,jp2;
ImageIcon i1;
JPasswordField pf1,cpf1;
JButton svbtn,exbtn,bkbtn,rsetbtn;
int a, b;
user nun1, nun2,nun3;
user users[];
Signup(){
// Frame Layout
frm = new JFrame("Signup page");
frm.setBounds(450, 80, 600, 650);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setResizable(false);
frm.setVisible(true);
frm.setLayout (null);
//logo
i1 = new ImageIcon("logo.png");
//Header
header = new JLabel("Sign Up");
header.setBounds(80, 50, 200, 100);
header.setForeground(Color.black);
header.setFont(new Font("Default",Font.BOLD,27));
// User Name
label1 = new JLabel("Name");
label1.setBounds(100, 147, 150, 70);
label1.setFont(new Font("Default",Font.BOLD,17));
// User Password
label2 = new JLabel("Password");
label2.setBounds(100, 205, 100, 50);
label2.setFont(new Font("Default",Font.BOLD,17));
// User password comform
label3 = new JLabel("Re-type Password");
label3.setBounds(100, 250, 200, 50);
label3.setFont(new Font("Default",Font.BOLD,17));
// User Email account
label4 = new JLabel("Email Account");
label4.setBounds(100, 300, 200, 50);
label4.setFont(new Font("Default",Font.BOLD,17));
// User Phone
label5 = new JLabel("Phone Number");
label5.setBounds(100, 352, 200, 50);
label5.setFont(new Font("Default",Font.BOLD,17));
// User name textfield adding.
tf1 = new JTextField();
tf1.setBounds(280, 170, 150, 22);
// password field adding.
pf1 = new JPasswordField();
pf1.setBounds(280, 220, 150, 22);
// pf1.setHorizontalAlignment(JTextField.CENTER);
//Comform password field adding.
cpf1 = new JPasswordField();
cpf1.setBounds(280, 265, 150, 22);
// cpf1.setHorizontalAlignment(JTextField.CENTER);
//Email textfield adding.
tf2 = new JTextField();
tf2.setBounds(280, 315, 150, 22);
// Phone Number textfield adding.
tf3 = new JTextField();
tf3.setBounds(280, 370, 150, 22);
// Save button Adding
svbtn = new JButton("Save");
svbtn.setBounds(300, 470, 100, 40);
svbtn.setBackground(Color.orange);
svbtn.addActionListener(this);
svbtn.setFont(new Font("Default",Font.BOLD,13));
// Back button
bkbtn = new JButton("Back");
bkbtn.setBounds(1, 1, 80, 30);
bkbtn.setForeground(Color.blue);
bkbtn.addActionListener(this);
bkbtn.setFont(new Font("Default",Font.BOLD,13));
// Exit button
exbtn = new JButton("Exit");
exbtn.setBounds(510, 1, 80, 30);
exbtn.setBackground(Color.orange);
exbtn.addActionListener(this);
exbtn.setFont(new Font("Default",Font.BOLD,13));
// Reset button Adding
rsetbtn = new JButton("Reset");
rsetbtn.setBounds(150, 470, 100, 40);
rsetbtn.addActionListener(this);
rsetbtn.setFont(new Font("Default",Font.BOLD,13));
// Captcha Label and Text Field
label6 = new JLabel();
label6.setText("Captcha");
label6.setBounds(100, 400, 200, 50);
label6.setFont(new Font("Default",Font.BOLD,15));
frm.add(label6);
tf5 = new JTextField();
tf5.setBounds(280, 410, 150, 25);
frm.add(tf1);
// To get a random number for captcha
Random rand = new Random();
int a = rand.nextInt(10);
int b = rand.nextInt(10);
// Captcha
lab7 = new JLabel();
lab7.setText(" " + a + " + " + b + " ");
lab7.setBounds(170, 410, 75, 30);
lab7.setForeground(Color.red);
lab7.setBackground(Color.decode("#FFD3D3"));
lab7.setOpaque(true);
//Adding Part
frm.add(header);
frm.add(label1);
frm.add(label2);
frm.add(label3);
frm.add(label4);
frm.add(label5);
frm.add(tf1);
frm.add(tf2);
frm.add(tf3);
frm.add(tf5);
frm.add(pf1);
frm.add(cpf1);
frm.add(exbtn);
frm.add(svbtn);
frm.add(bkbtn);
frm.add(rsetbtn);
frm.add(lab7);
frm.setIconImage(i1.getImage());
}
// Action Part
public void actionPerformed(ActionEvent e) {
String user = tf1.getText().toLowerCase();
String pass = pf1.getText().toLowerCase();
String email = tf2.getText();
String captcha = tf5.getText();
if (e.getSource() == svbtn) {
int flag = 0;
if(user.isEmpty()==false && pass.isEmpty()==false && email.isEmpty()==false && captcha.isEmpty()==false)
{
for(int i = 0; i<users.length; i++)
{
if(users[i]!=null)
{
flag = 1;
break;
}
}
if (flag == 1)
{
frm.setVisible(false);
}
else
{
showMessageDialog(null, "Invalid Username or password!");
}
}
else
{
showMessageDialog(null,"Fillup Every Field.");
}
}
int result = 0;
if (result != (a + b)) {
JOptionPane.showMessageDialog(null, "Wrong Captcha.", "Warning!", JOptionPane.WARNING_MESSAGE);}
if(e.getSource()==exbtn)
{
System.exit(0);
}
if(e.getSource()==bkbtn)
{
new LogInPage();
frm.setVisible(false);
}
if(e.getSource()==rsetbtn)
{
new Signup();
frm.setVisible(false);
}
}
}