-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignupPanel.java
More file actions
177 lines (148 loc) · 6.22 KB
/
Copy pathSignupPanel.java
File metadata and controls
177 lines (148 loc) · 6.22 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
package banking.panels;
import javax.swing.*;
import java.awt.*;
import banking.BankingGUI;
import banking.StyledComponents;
public class SignupPanel extends JPanel {
public SignupPanel(BankingGUI app) {
setLayout(new BorderLayout());
setBackground(BankingGUI.BACKGROUND);
// Header
JPanel header = StyledComponents.createGradientPanel(
new Color(16, 185, 129),
new Color(5, 150, 105)
);
header.setPreferredSize(new Dimension(750, 100));
header.setLayout(new GridBagLayout());
JLabel headerLabel = new JLabel("Create Your Account");
headerLabel.setFont(new Font("Segoe UI", Font.BOLD, 28));
headerLabel.setForeground(Color.WHITE);
header.add(headerLabel);
// Main Card
JPanel mainCard = new JPanel();
mainCard.setBackground(BankingGUI.CARD_BG);
mainCard.setLayout(new GridBagLayout());
mainCard.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(55, 65, 81), 2),
BorderFactory.createEmptyBorder(30, 50, 30, 50)
));
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(8, 8, 8, 8);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.anchor = GridBagConstraints.CENTER;
// Username Label
JLabel userLabel = createLabel("Username");
gbc.gridy = 0;
mainCard.add(userLabel, gbc);
// Username Field
JTextField nameField = createModernTextField();
gbc.gridy = 1;
mainCard.add(nameField, gbc);
// Password Label
JLabel passLabel = createLabel("Password (4 digits)");
gbc.gridy = 2;
mainCard.add(passLabel, gbc);
// Password Field
JPasswordField passField = createModernPasswordField();
gbc.gridy = 3;
mainCard.add(passField, gbc);
// Confirm Password Label
JLabel confirmLabel = createLabel("Confirm Password");
gbc.gridy = 4;
mainCard.add(confirmLabel, gbc);
// Confirm Password Field
JPasswordField confirmField = createModernPasswordField();
gbc.gridy = 5;
mainCard.add(confirmField, gbc);
// Buttons Panel - SIDE BY SIDE
JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 10, 0));
buttonPanel.setOpaque(false);
buttonPanel.setPreferredSize(new Dimension(320, 45));
JButton createBtn = StyledComponents.createStyledButton(
"Create Account",
new Color(16, 185, 129),
Color.WHITE,
150,
45
);
JButton backBtn = StyledComponents.createStyledButton(
"Back",
new Color(75, 85, 99),
Color.WHITE,
150,
45
);
buttonPanel.add(createBtn);
buttonPanel.add(backBtn);
gbc.gridy = 6;
gbc.insets = new Insets(20, 8, 8, 8);
mainCard.add(buttonPanel, gbc);
// Wrapper with ScrollPane
JPanel wrapper = new JPanel(new GridBagLayout());
wrapper.setBackground(BankingGUI.BACKGROUND);
wrapper.add(mainCard);
JScrollPane scrollPane = new JScrollPane(wrapper);
scrollPane.setBorder(null);
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
scrollPane.setBackground(BankingGUI.BACKGROUND);
add(header, BorderLayout.NORTH);
add(scrollPane, BorderLayout.CENTER);
// Action Listeners
backBtn.addActionListener(e -> app.showPanel(BankingGUI.WELCOME_PANEL));
createBtn.addActionListener(e -> {
try {
String pass = new String(passField.getPassword());
if (!pass.equals(new String(confirmField.getPassword()))) {
showError("Passwords don't match!");
return;
}
if (app.getService().createAccount(nameField.getText().trim(), Integer.parseInt(pass))) {
showSuccess("Account created successfully!");
app.showPanel(BankingGUI.LOGIN_PANEL);
}
} catch(Exception ex) {
showError("Error creating account. Check your input.");
}
});
confirmField.addActionListener(e -> createBtn.doClick());
}
private JLabel createLabel(String text) {
JLabel label = new JLabel(text);
label.setFont(new Font("Segoe UI", Font.BOLD, 13));
label.setForeground(new Color(209, 213, 219));
return label;
}
private JTextField createModernTextField() {
JTextField field = new JTextField(20);
field.setFont(new Font("Segoe UI", Font.PLAIN, 14));
field.setPreferredSize(new Dimension(320, 38));
field.setBackground(new Color(31, 41, 55));
field.setForeground(Color.WHITE);
field.setCaretColor(Color.WHITE);
field.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(75, 85, 99), 2),
BorderFactory.createEmptyBorder(6, 12, 6, 12)
));
return field;
}
private JPasswordField createModernPasswordField() {
JPasswordField field = new JPasswordField(20);
field.setFont(new Font("Segoe UI", Font.PLAIN, 14));
field.setPreferredSize(new Dimension(320, 38));
field.setBackground(new Color(31, 41, 55));
field.setForeground(Color.WHITE);
field.setCaretColor(Color.WHITE);
field.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(75, 85, 99), 2),
BorderFactory.createEmptyBorder(6, 12, 6, 12)
));
return field;
}
private void showError(String message) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
}
private void showSuccess(String message) {
JOptionPane.showMessageDialog(this, message, "Success", JOptionPane.INFORMATION_MESSAGE);
}
}