-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignUpPage.java
More file actions
executable file
·205 lines (170 loc) · 6.16 KB
/
Copy pathSignUpPage.java
File metadata and controls
executable file
·205 lines (170 loc) · 6.16 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
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
public class SignUpPage {
private JFrame frame;
private JTextField textFieldUserNameSignUp;
private JPasswordField passwordFieldSignUp;
private JTextField textFieldFirstName;
private JTextField textFieldLastName;
private JTextField textFieldEmail;
/**
* Launch the application.
*/
public static void SignUp() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SignUpPage window = new SignUpPage();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public SignUpPage() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 830, 758);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("Guessing game ");
lblNewLabel.setFont(new Font("Algerian", Font.PLAIN, 30));
lblNewLabel.setBounds(286, 13, 300, 66);
frame.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Enter your user name");
lblNewLabel_1.setBounds(102, 402, 127, 35);
frame.getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Enter your password");
lblNewLabel_2.setBounds(102, 475, 127, 35);
frame.getContentPane().add(lblNewLabel_2);
textFieldUserNameSignUp = new JTextField();
textFieldUserNameSignUp.setBounds(280, 400, 306, 38);
frame.getContentPane().add(textFieldUserNameSignUp);
textFieldUserNameSignUp.setColumns(10);
passwordFieldSignUp = new JPasswordField();
passwordFieldSignUp.setBounds(280, 473, 306, 38);
frame.getContentPane().add(passwordFieldSignUp);
JButton btnConfirmSignUp = new JButton("Confirm");
btnConfirmSignUp.setBounds(102, 611, 140, 38);
frame.getContentPane().add(btnConfirmSignUp);
JButton btnCancel = new JButton("Cancel");
btnCancel.setBounds(459, 611, 140, 38);
frame.getContentPane().add(btnCancel);
JLabel lblNewLabel_3 = new JLabel("Enter your email");
lblNewLabel_3.setBounds(102, 338, 127, 16);
frame.getContentPane().add(lblNewLabel_3);
JLabel lblNewLabel_4 = new JLabel("Enter your last name");
lblNewLabel_4.setBounds(102, 272, 127, 16);
frame.getContentPane().add(lblNewLabel_4);
JLabel lblNewLabel_5 = new JLabel("Enter your first name");
lblNewLabel_5.setBounds(102, 195, 127, 16);
frame.getContentPane().add(lblNewLabel_5);
textFieldFirstName = new JTextField();
textFieldFirstName.setBounds(280, 184, 306, 38);
frame.getContentPane().add(textFieldFirstName);
textFieldFirstName.setColumns(10);
textFieldLastName = new JTextField();
textFieldLastName.setBounds(280, 261, 306, 38);
frame.getContentPane().add(textFieldLastName);
textFieldLastName.setColumns(10);
textFieldEmail = new JTextField();
textFieldEmail.setBounds(280, 327, 306, 38);
frame.getContentPane().add(textFieldEmail);
textFieldEmail.setColumns(10);
JButton btnReset = new JButton("Reset");
btnReset.setBounds(279, 611, 140, 38);
frame.getContentPane().add(btnReset);
// Confirm button event handler
btnConfirmSignUp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// No empty input allow
if (emptyChecking()) {
JOptionPane.showMessageDialog(null, " Unvalid input.\n Please try again");
}
else {
// Update the user's data to the database
if(signUpPasswordChecking()) {
JOptionPane.showMessageDialog(null, " Successfully add your information in the database !");
frame.dispose();
LoginPage loginPage = new LoginPage();
loginPage.run();
}
// Existing data inside the database
else {
JOptionPane.showMessageDialog(null, " Existing email or username .\n Please try again");
}
}
}
});
// Reset button event handler
btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Clear all the text fields
textFieldFirstName.setText("");
textFieldLastName.setText("");
textFieldEmail.setText("");
textFieldUserNameSignUp.setText("");
passwordFieldSignUp.setText("");
}
});
// Cancel button event handler
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Redirect to login page
LoginPage loginPage = new LoginPage();
loginPage.run();
frame.dispose();
}
});
}
private boolean signUpPasswordChecking() {
// Variable that will determine whether the email, username and password are valid or not
String firstName = textFieldFirstName.getText();
String lastName = textFieldLastName.getText();
String userName = textFieldUserNameSignUp.getText();
String email = textFieldEmail.getText();
String signUpUserName = textFieldUserNameSignUp.getText();
String signUpPassword = "";
// Retrieve password
char[] password = passwordFieldSignUp.getPassword();
// Convert char array to string
for(char values : password) {
signUpPassword += values;
}
// Compare the email, username and password with those in the database
// If exists in the database then return false
// If not then return true
return Client.signup(userName, email, signUpPassword, firstName, lastName);
}
private boolean emptyChecking() {
// Variable that will help determine empty fields
boolean check = false;
if( textFieldFirstName.getText().isEmpty() ||
textFieldLastName.getText().isEmpty() ||
textFieldEmail.getText().isEmpty() ||
textFieldUserNameSignUp.getText().isEmpty() ||
(passwordFieldSignUp.getPassword().equals(null))
)
{
check = true;
}
return check;
}
}