-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateProfileGUI.java
234 lines (205 loc) · 7.01 KB
/
CreateProfileGUI.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* This class displays a create profile GUI to the user.
*
* @author Jorah Hinman, Chandra Adhikari, Phil Gore
*/
@SuppressWarnings("serial")
public class CreateProfileGUI extends LoginGUI {
private JPanel mainPanel;
private JButton returnButton;
private JButton signupButton;
private ButtonListener buttonListener;
private JTextField username;
private JTextField password;
private JTextField firstName;
private JTextField lastName;
private JTextField email;
private JTextField passwordConfirm;
private AccountManager acct;
public CreateProfileGUI() {
initInstanceVars();
}
public CreateProfileGUI(AccountManager acct) {
this();
this.acct = acct;
}
private void initInstanceVars() {
acct = new AccountManager();
setLayout(new BorderLayout());
mainPanel = new JPanel();
buttonListener = new ButtonListener();// create button listener
createSignUpPage();
add(mainPanel);
}
private void createSignUpPage() {
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
centerPanel.add(initFirstNamePanel());
centerPanel.add(initLastNamePanel());
centerPanel.add(initUserNamePanel());
centerPanel.add(initEmailPanel());
centerPanel.add(initPasswordPanel());
centerPanel.add(initButtonPanel());
mainPanel.add(centerPanel);
}
private JPanel initUserNamePanel(){
JPanel userNamePanel = new JPanel();
userNamePanel.setLayout(new GridLayout(2,1));
JLabel userNameLabel = new JLabel("Username: ");
userNameLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
userNamePanel.add(userNameLabel);
username = new JTextField(20);
userNamePanel.add(username);
return userNamePanel;
}
private JPanel initFirstNamePanel(){
JPanel firstNamePanel = new JPanel();
firstNamePanel.setLayout(new GridLayout(2,1));
JLabel firstNameLabel = new JLabel("First name: ");
firstNameLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
firstNamePanel.add(firstNameLabel);
firstName = new JTextField(20);
firstNamePanel.add(firstName);
return firstNamePanel;
}
private JPanel initLastNamePanel(){
JPanel lastNamePanel = new JPanel();
lastNamePanel.setLayout(new GridLayout(2,1));
JLabel lastNameLabel = new JLabel("Last name: ");
lastNameLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
lastNamePanel.add(lastNameLabel);
lastName = new JTextField(20);
lastNamePanel.add(lastName);
return lastNamePanel;
}
private JPanel initEmailPanel(){
JPanel emailPanel = new JPanel();
emailPanel.setLayout(new GridLayout(2,1));
JLabel emailLabel = new JLabel("Email: ");
emailLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
emailPanel.add(emailLabel);
email= new JTextField(20);
emailPanel.add(email);
return emailPanel;
}
private JPanel initPasswordPanel(){
JPanel passwordPanel = new JPanel();
passwordPanel.setLayout(new GridLayout(6, 1));
JLabel passwordLabel = new JLabel("Password: ");
passwordLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
passwordPanel.add(passwordLabel);
password = new JTextField(20);
passwordPanel.add(password);
JLabel confirmLabel = new JLabel("Confirm password: ");
confirmLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
passwordPanel.add(confirmLabel);
passwordConfirm = new JTextField(20);
passwordPanel.add(passwordConfirm);
return passwordPanel;
}
private JPanel initButtonPanel(){
JPanel buttonPanel = new JPanel();
signupButton = new JButton("Create Profile!");
signupButton.addActionListener(buttonListener);
signupButton.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
buttonPanel.add(signupButton);
returnButton = new JButton("Return");
returnButton.addActionListener(buttonListener);
returnButton.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
buttonPanel.add(returnButton);
return buttonPanel;
}
private boolean createNewProfile(String first, String last, String email, String usrName, String pass) {
UserProfile newUser = new UserProfile();
newUser.setFirstName(first);
newUser.setLastName(last);
newUser.setEmail(email);
newUser.setUserName(usrName);
newUser.setPassword(pass);
if (verifyProfileInformation(newUser)) {
acct.put(newUser);
return true;
} else {
return false;
}
}
private boolean verifyProfileInformation(UserProfile newUser) {
if (acct.verifyCreateProfile(newUser, "")) {
return true;
} else {
return false;
}
}
private class ButtonListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(signupButton)) {
if (!checkForBlanks()) {
if (password.getText().equals(passwordConfirm.getText())) {
if (createNewProfile(firstName.getText(), lastName.getText(), email.getText(),
username.getText(), password.getText())) {
JOptionPane.showMessageDialog(null, "Account Created! Welcome!", null,
JOptionPane.PLAIN_MESSAGE);
removeAll();
add(new LoginGUI(acct));
repaint();
revalidate();
setPreferredSize(new Dimension(800, 800));
setVisible(true);
}
} else {
JOptionPane.showMessageDialog(null, "Password Mismatch", null, JOptionPane.PLAIN_MESSAGE);
}
}
}
if (e.getSource().equals(returnButton)) {
removeAll();
add(new LandingPageGUI(acct));
repaint();
revalidate();
setPreferredSize(new Dimension(800, 800));
setVisible(true);
}
}
}
public boolean checkForBlanks() {
boolean hasBlank = false;
if (firstName.getText().equals("")) {
hasBlank = true;
JOptionPane.showMessageDialog(null, "First name is required.", null, JOptionPane.PLAIN_MESSAGE);
}
if (lastName.getText().equals("")) {
hasBlank = true;
JOptionPane.showMessageDialog(null, "Last name is required.", null, JOptionPane.PLAIN_MESSAGE);
}
if (username.getText().equals("")) {
hasBlank = true;
JOptionPane.showMessageDialog(null, "Username is required.", null, JOptionPane.PLAIN_MESSAGE);
}
if (email.getText().equals("")) {
hasBlank = true;
JOptionPane.showMessageDialog(null, "Email is required.", null, JOptionPane.PLAIN_MESSAGE);
}
if (password.getText().equals("")) {
hasBlank = true;
JOptionPane.showMessageDialog(null, "Password is required.", null, JOptionPane.PLAIN_MESSAGE);
}
if (passwordConfirm.getText().equals("")) {
hasBlank = true;
JOptionPane.showMessageDialog(null, "Confirm Password is required.", null, JOptionPane.PLAIN_MESSAGE);
}
return hasBlank;
}
}