-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSellerSignUpWindow.java
181 lines (135 loc) · 5.31 KB
/
SellerSignUpWindow.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
package C212Amazon;
import javax.swing.*;
import java.awt.*;
/**
* A class to represent a sign up gui for a seller.
* @author Syed Turab Ali Jafri
* 4/22/2017
*/
public class SellerSignUpWindow extends SignUpWindow {
private SellerDataWriter sellerdatawriter = new SellerDataWriter();
private SellerDataReader sellerdatareader = new SellerDataReader();
private JLabel nameLabel = new JLabel("Name: ");
private JTextField nameTextField = new JTextField(20);
private JLabel phoneLabel = new JLabel("Phone: ");
private JTextField phoneTextField = new JTextField(20);
public SellerSignUpWindow() {
super("Seller");
setPanelSizeAndLayout();
setLeftPanel();
setRightPanel();
setBottomPanel();
signUpButton.addActionListener(e -> setSignUpButton());
setLocationRelativeTo(null);
setVisible(true);
}
protected void setLeftPanel(){
JPanel leftPanel = new JPanel();
leftPanel.setLayout(new GridLayout(9,2));
leftPanel.add(new JPanel());
leftPanel.add(new JPanel());
leftPanel.add(new JPanel());
leftPanel.add(new JPanel());
nameLabel.setHorizontalAlignment(4);
leftPanel.add(new JPanel());
leftPanel.add(nameLabel);
usernameLabel.setHorizontalAlignment(4);
leftPanel.add(new JPanel());
leftPanel.add(usernameLabel);
passwordLabel.setHorizontalAlignment(4);
leftPanel.add(new JPanel());
leftPanel.add(passwordLabel);
confirmPasswordLabel.setHorizontalAlignment(4);
leftPanel.add(new JPanel());
leftPanel.add(confirmPasswordLabel);
phoneLabel.setHorizontalAlignment(4);
leftPanel.add(new JPanel());
leftPanel.add(phoneLabel);
emailAddressLabel.setHorizontalAlignment(4);
leftPanel.add(new JPanel());
leftPanel.add(emailAddressLabel);
mainPanel.add(leftPanel,BorderLayout.WEST);
}
protected void setRightPanel(){
JPanel rightPanel = new JPanel();
rightPanel.setLayout(new GridLayout(9,2));
rightPanel.add(new JPanel());
rightPanel.add(new JPanel());
rightPanel.add(new JPanel());
rightPanel.add(new JPanel());
rightPanel.add(nameTextField);
rightPanel.add(new JPanel());
rightPanel.add(usernameTextField);
rightPanel.add(new JPanel());
rightPanel.add(passwordTextField);
rightPanel.add(new JPanel());
rightPanel.add(confirmedPasswordTextField);
rightPanel.add(new JPanel());
rightPanel.add(phoneTextField);
rightPanel.add(new JPanel());
rightPanel.add(emailAddressTextField);
rightPanel.add(new JPanel());
mainPanel.add(rightPanel,BorderLayout.EAST);
}
private void setSignUpButton() {
JOptionPane jop = new JOptionPane();
int errors = 0;
String error = "";
boolean usernameExists = true;
if (sellerdatareader.verifyNewUsername("seller", usernameTextField.getText())) {
usernameExists = false;
if (usernameTextField.getText().length() < 4) {
errors++;
error += "Invalid username (4)\n";
usernameTextField.setText("");
}
if (passwordTextField.getText().length() < 8) {
errors++;
error += "Invalid password (8)\n";
passwordTextField.setText("");
confirmedPasswordTextField.setText("");
}
else if(!confirmedPasswordTextField.getText().equals(passwordTextField.getText())) {
errors++;
error += "Passwords don't match.\n";
passwordTextField.setText("");
confirmedPasswordTextField.setText("");
}
if (nameTextField.getText().length() < 3) {
errors++;
error += "Invalid name (3)\n";
nameTextField.setText("");
}
if (phoneTextField.getText().length() < 10) {
errors++;
error += "Invalid phone number (10)\n";
phoneTextField.setText("");
}
if (emailAddressTextField.getText().length() < 5) {
errors++;
error += "Invalid email address (5)\n";
emailAddressTextField.setText("");
}
}
if(usernameExists) {
errors++;
error += "Username already exists!\n";
usernameTextField.setText("");
}
if(errors == 0) {
if(!sellerdatawriter.createSeller(new Seller(0,usernameTextField.getText(), passwordTextField.getText(),
nameTextField.getText(), phoneTextField.getText(),
emailAddressTextField.getText()))) {
jop.showMessageDialog(null, "Error while creating user. Please try again.",
"Writing Error", JOptionPane.ERROR_MESSAGE);
}
else {
jop.showMessageDialog(null, "Seller created successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
}
}
else {
jop.showMessageDialog(null, "Errors (" + errors + ")\n" + error, "Error", JOptionPane.ERROR_MESSAGE);
}
}
}