-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistrationFrame.java
More file actions
183 lines (154 loc) · 6.46 KB
/
Copy pathRegistrationFrame.java
File metadata and controls
183 lines (154 loc) · 6.46 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
package vhs;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
public class RegistrationFrame extends JFrame {
private JComboBox<String> userTypeCombo;
private JPanel dynamicPanel;
private CardLayout cardLayout;
private List<User> users;
private LoginFrame loginFrame;
public RegistrationFrame(List<User> users, LoginFrame loginFrame) {
this.users = users;
this.loginFrame = loginFrame;
setTitle("Register - Virtual Healthcare System");
setSize(500, 400);
setLocationRelativeTo(loginFrame);
setLayout(new BorderLayout());
initializeComponents();
}
private void initializeComponents() {
// User Type Selection
JPanel typePanel = new JPanel(new FlowLayout());
typePanel.add(new JLabel("Register as:"));
userTypeCombo = new JComboBox<>(new String[]{"Patient", "Provider", "Admin"});
userTypeCombo.addActionListener(e -> showRegistrationForm());
typePanel.add(userTypeCombo);
// Dynamic Forms Panel
cardLayout = new CardLayout();
dynamicPanel = new JPanel(cardLayout);
// Add forms
dynamicPanel.add(createPatientForm(), "PATIENT");
dynamicPanel.add(createProviderForm(), "PROVIDER");
dynamicPanel.add(createAdminForm(), "ADMIN");
add(typePanel, BorderLayout.NORTH);
add(dynamicPanel, BorderLayout.CENTER);
showRegistrationForm();
}
private JPanel createPatientForm() {
JPanel panel = new JPanel(new GridLayout(7, 2, 10, 10));
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JTextField idField = new JTextField("P" + (users.size() + 100));
JTextField nameField = new JTextField();
JTextField emailField = new JTextField();
JPasswordField passwordField = new JPasswordField();
JTextField medicalField = new JTextField();
JTextField contactField = new JTextField();
panel.add(new JLabel("Patient ID:"));
panel.add(idField);
panel.add(new JLabel("Full Name:"));
panel.add(nameField);
panel.add(new JLabel("Email:"));
panel.add(emailField);
panel.add(new JLabel("Password:"));
panel.add(passwordField);
panel.add(new JLabel("Medical History:"));
panel.add(medicalField);
panel.add(new JLabel("Contact Number:"));
panel.add(contactField);
JButton registerBtn = new JButton("Register Patient");
registerBtn.addActionListener(e -> {
Patient patient = new Patient(
idField.getText(),
nameField.getText(),
emailField.getText(),
new String(passwordField.getPassword()),
medicalField.getText(),
contactField.getText(),
"Emergency: " + contactField.getText()
);
users.add(patient);
JOptionPane.showMessageDialog(this, "Patient registered successfully!");
dispose();
});
panel.add(new JLabel(""));
panel.add(registerBtn);
return panel;
}
private JPanel createProviderForm() {
JPanel panel = new JPanel(new GridLayout(6, 2, 10, 10));
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JTextField idField = new JTextField("PR" + (users.size() + 100));
JTextField nameField = new JTextField();
JTextField emailField = new JTextField();
JPasswordField passwordField = new JPasswordField();
JTextField specialtyField = new JTextField();
panel.add(new JLabel("Provider ID:"));
panel.add(idField);
panel.add(new JLabel("Full Name:"));
panel.add(nameField);
panel.add(new JLabel("Email:"));
panel.add(emailField);
panel.add(new JLabel("Password:"));
panel.add(passwordField);
panel.add(new JLabel("Specialty:"));
panel.add(specialtyField);
JButton registerBtn = new JButton("Register Provider");
registerBtn.addActionListener(e -> {
Provider provider = new Provider(
idField.getText(),
nameField.getText(),
emailField.getText(),
new String(passwordField.getPassword()),
specialtyField.getText(),
"LIC-" + System.currentTimeMillis()
);
users.add(provider);
JOptionPane.showMessageDialog(this, "Provider registered successfully!");
dispose();
});
panel.add(new JLabel(""));
panel.add(registerBtn);
return panel;
}
private JPanel createAdminForm() {
JPanel panel = new JPanel(new GridLayout(5, 2, 10, 10));
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JTextField idField = new JTextField("A" + (users.size() + 100));
JTextField nameField = new JTextField();
JTextField emailField = new JTextField();
JPasswordField passwordField = new JPasswordField();
JTextField deptField = new JTextField();
panel.add(new JLabel("Admin ID:"));
panel.add(idField);
panel.add(new JLabel("Full Name:"));
panel.add(nameField);
panel.add(new JLabel("Email:"));
panel.add(emailField);
panel.add(new JLabel("Password:"));
panel.add(passwordField);
panel.add(new JLabel("Department:"));
panel.add(deptField);
JButton registerBtn = new JButton("Register Admin");
registerBtn.addActionListener(e -> {
Admin admin = new Admin(
idField.getText(),
nameField.getText(),
emailField.getText(),
new String(passwordField.getPassword()),
deptField.getText()
);
users.add(admin);
JOptionPane.showMessageDialog(this, "Admin registered successfully!");
dispose();
});
panel.add(new JLabel(""));
panel.add(registerBtn);
return panel;
}
private void showRegistrationForm() {
String userType = ((String) userTypeCombo.getSelectedItem()).toUpperCase();
cardLayout.show(dynamicPanel, userType);
}
}