forked from Samiullah-Kalhoro/hacktoberfest_21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistrationForm
236 lines (191 loc) · 8.08 KB
/
RegistrationForm
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package oopclasstask;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
/**
*
* @author HP
*/
public class RegistrationForm extends JFrame implements ActionListener{
JLabel AppName;
JLabel title;
JTextField nameT;
JLabel name;
JPasswordField pass;
JLabel pass1;
JTextField email;
JLabel email1;
JTextField nameT2;
JLabel name2;
JTextField gender;
JLabel gender1;
JTextField city;
JLabel city1;
JTextField country;
JLabel country1;
JTextField phone;
JLabel phone1;
JButton sumbit;
JButton clear;
JCheckBox checkBox;
JRadioButton male;
JRadioButton female;
ButtonGroup group;
RegistrationForm(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 900);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(0,0,500,860);
panel.setBackground(new Color(0x00ff4d));
panel.setLayout(null);
this.add(panel);
AppName = new JLabel("OOP Task");
AppName.setFont(new Font("Comic Sans", Font.BOLD, 45));
AppName.setForeground(Color.BLUE);
AppName.setBounds(140, 100, 250, 50);
title = new JLabel("Registration");
title.setFont(new Font("Comic Sans", Font.BOLD, 35));
title.setForeground(Color.BLUE);
title.setBounds(150, 150, 200, 50);
name = new JLabel("Name:");
name.setBounds(120, 270, 50, 35);
nameT = new JTextField();
nameT.setBounds(180, 270, 150, 30);
pass1 = new JLabel("Password:");
pass1.setBounds(100, 320, 100, 35);
pass = new JPasswordField();
pass.setBounds(180, 320, 150, 30);
email1 = new JLabel("Email:");
email1.setBounds(120, 370, 50, 35);
email = new JTextField();
// email.setText("[email protected]");
email.setBounds(180, 370, 150, 30);
gender1 = new JLabel("Gender:");
gender1.setBounds(110, 420, 50, 35);
// gender = new JTextField();
// //gender.setBounds(210, 450, 150, 30);
city1 = new JLabel("City:");
city1.setBounds(130, 470, 50, 35);
city = new JTextField();
city.setBounds(180, 470, 150, 30);
country1 = new JLabel("Country:");
country1.setBounds(110, 520, 50, 35);
country = new JTextField();
country.setBounds(180, 520, 150, 30);
phone1 = new JLabel("Phone No:");
phone1.setBounds(100, 570, 90, 35);
phone = new JTextField();
phone.setBounds(180, 570, 150, 30);
sumbit = new JButton("Sumbit");
sumbit.setBounds(100, 720, 80, 35);
clear = new JButton("Clear");
clear.setBounds(220, 720, 70, 35);
checkBox = new JCheckBox();
checkBox.setText("Terms & Conditions.");
checkBox.setBounds(150, 620, 150, 50);
checkBox.setBackground(new Color(0x00ff4d));
male = new JRadioButton("Male");
male.setBounds(180, 420, 70, 30);
male.setBackground(new Color(0x00ff4d));
female = new JRadioButton("Female");
female.setBounds(250, 420, 70, 30);
female.setBackground(new Color(0x00ff4d));
group = new ButtonGroup();
group.add(male);
group.add(female);
sumbit.addActionListener(this);
clear.addActionListener(this);
//DEBUGGING PART
//String nameq = email.getText();
//System.out.println(nameq);
//System.out.println(nameq.contains("gmail"));
//System.out.println(group.getSelection());
//String numbers = phone.getText();
//System.out.println(numbers);
//System.out.println(checkBox.isSelected());
panel.add(AppName);
panel.add(title);
panel.add(name);
panel.add(nameT);
panel.add(pass1);
panel.add(pass);
panel.add(email1);
panel.add(email);
panel.add(gender1);
panel.add(city1);
panel.add(city);
panel.add(country1);
panel.add(country);
panel.add(phone1);
panel.add(phone);
panel.add(sumbit);
panel.add(clear);
panel.add(checkBox);
panel.add(male);
panel.add(female);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==sumbit){
String nameq = email.getText();
String number = phone.getText();
//String[] numbers = {"a", "b", "c"};
if(nameT.getText().equals(""))
JOptionPane.showMessageDialog(null, "Enter name first!");
else if(pass.getText().equals(""))
JOptionPane.showMessageDialog(null, "Enter your password!");
else if(!nameq.contains("@gmail.com"))
JOptionPane.showMessageDialog(null, "Please enter correct email!");
else if(group.getSelection()== null)
JOptionPane.showMessageDialog(null, "Select your Gender!");
else if(number.contains("a")|| number.contains("b") || number.contains("c")|| number.contains("d")
|| number.contains("e")|| number.contains("f") || number.contains("g")|| number.contains("h")
|| number.contains("i")|| number.contains("j") || number.contains("k")|| number.contains("l") || number.contains("m")|| number.contains("n")
|| number.contains("o")|| number.contains("p") || number.contains("q")|| number.contains("r")
|| number.contains("s")|| number.contains("t") || number.contains("u")|| number.contains("v") || number.contains("w")|| number.contains("x")
|| number.contains("y")|| number.contains("z") || number.contains("A")|| number.contains("B")
|| number.contains("C")|| number.contains("D") || number.contains("E")|| number.contains("F") || number.contains("G")|| number.contains("H")
|| number.contains("I")|| number.contains("J") || number.contains("K")|| number.contains("L")
|| number.contains("M")|| number.contains("N") || number.contains("O")|| number.contains("P") || number.contains("Q")|| number.contains("R")
|| number.contains("S")|| number.contains("T") || number.contains("U")|| number.contains("V")
|| number.contains("W")|| number.contains("X") || number.contains("Y")|| number.contains("Z") || number.contains("@")|| number.contains("#")
|| number.contains("!")|| number.contains("$") || number.contains("%")|| number.contains("&")
|| number.contains("*")|| number.contains("+"))
JOptionPane.showMessageDialog(null, "Invalid number!");
else if(checkBox.isSelected()== false)
JOptionPane.showMessageDialog(null, "Please accept Terms & Conditions");
else
JOptionPane.showMessageDialog(null, "Registration Successful");
}
else if(ae.getSource()==clear){
nameT.setText("");
pass.setText("");
email.setText("");
city.setText("");
country.setText("");
phone.setText("");
group.clearSelection();
checkBox.setSelected(false);
}
}
}