Repository navigation
Expand file tree
/
Copy pathReceptionistSystemSwing.java
More file actions
331 lines (287 loc) · 12.2 KB
/
Copy pathReceptionistSystemSwing.java
File metadata and controls
331 lines (287 loc) · 12.2 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.HashMap;
public class ReceptionistSystemSwing {
private static HashMap<Integer, Patient> roomAssignments = new HashMap<>();
private static HashMap<String, Appointment> appointments = new HashMap<>();
public static void main(String[] args) {
ReceptionistSystemSwing system = new ReceptionistSystemSwing();
system.runSystem();
}
private void runSystem() {
loadRoomData();
loadAppointmentData();
showManagementMenu();
}
private void loadRoomData() {
try (BufferedReader reader = new BufferedReader(new FileReader("rooms.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
int roomNumber = Integer.parseInt(parts[0]);
int bedNumber = Integer.parseInt(parts[1]);
String name = parts[2];
String disease = parts[3];
String complications = parts[4];
Patient patient = new Patient(roomNumber, bedNumber, name, disease, complications);
roomAssignments.put(roomNumber, patient);
}
} catch (IOException e) {
System.out.println("No room data found. Starting fresh.");
} catch (NumberFormatException e) {
System.out.println("Invalid data format in rooms.txt. Starting fresh.");
}
}
private void loadAppointmentData() {
try (BufferedReader reader = new BufferedReader(new FileReader("appointments.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
String patientName = parts[0];
String date = parts[1];
String time = parts[2];
String doctor = parts[3];
String reason = parts[4];
Appointment appointment = new Appointment(patientName, date, time, doctor, reason);
appointments.put(patientName, appointment);
}
} catch (IOException e) {
System.out.println("No appointment data found. Starting fresh.");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Invalid data format in appointments.txt. Starting fresh.");
}
}
private void saveRoomData() {
try (PrintWriter writer = new PrintWriter(new FileWriter("rooms.txt"))) {
for (Patient patient : roomAssignments.values()) {
writer.println(patient.toFileFormat());
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void saveAppointmentData() {
try (PrintWriter writer = new PrintWriter(new FileWriter("appointments.txt"))) {
for (Appointment appointment : appointments.values()) {
writer.println(appointment.toFileFormat());
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void showManagementMenu() {
JFrame frame = new JFrame("Receptionist Management System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200, 800);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(5, 1, 10, 10));
panel.setBackground(new Color(245, 245, 245));
JButton assignRoomButton = createStyledButton("Assign a Room");
JButton scheduleAppointmentButton = createStyledButton("Schedule an Appointment");
JButton viewDataButton = createStyledButton("View Data");
JButton exitButton = createStyledButton("Exit");
assignRoomButton.addActionListener(e -> showAssignRoomScreen());
scheduleAppointmentButton.addActionListener(e -> showScheduleAppointmentScreen());
viewDataButton.addActionListener(e -> showViewDataScreen());
exitButton.addActionListener(e -> {
saveRoomData();
saveAppointmentData();
JOptionPane.showMessageDialog(frame, "Data saved. Goodbye!");
frame.dispose();
});
panel.add(assignRoomButton);
panel.add(scheduleAppointmentButton);
panel.add(viewDataButton);
panel.add(exitButton);
frame.add(panel);
frame.setVisible(true);
}
private JButton createStyledButton(String text) {
JButton button = new JButton(text);
button.setFont(new Font("Arial", Font.PLAIN, 25));
button.setBackground(new Color(70, 130, 180));
button.setForeground(Color.WHITE);
button.setFocusPainted(false);
button.setPreferredSize(new Dimension(200, 50));
button.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
return button;
}
private void showAssignRoomScreen() {
JFrame frame = new JFrame("Assign a Room");
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(7, 2, 10, 10));
panel.setBackground(new Color(245, 245, 245));
JLabel roomLabel = new JLabel("Room Number:");
JTextField roomField = new JTextField();
JLabel bedLabel = new JLabel("Bed Number:");
JTextField bedField = new JTextField();
JLabel nameLabel = new JLabel("Patient Name:");
JTextField nameField = new JTextField();
JLabel diseaseLabel = new JLabel("Disease:");
JTextField diseaseField = new JTextField();
JLabel complicationsLabel = new JLabel("Complications:");
JTextField complicationsField = new JTextField();
JButton assignButton = new JButton("Assign");
Font font = new Font("Arial", Font.PLAIN, 25);
roomLabel.setFont(font);
bedLabel.setFont(font);
nameLabel.setFont(font);
diseaseLabel.setFont(font);
complicationsLabel.setFont(font);
roomField.setFont(font);
bedField.setFont(font);
nameField.setFont(font);
diseaseField.setFont(font);
complicationsField.setFont(font);
assignButton.setFont(font);
panel.add(roomLabel);
panel.add(roomField);
panel.add(bedLabel);
panel.add(bedField);
panel.add(nameLabel);
panel.add(nameField);
panel.add(diseaseLabel);
panel.add(diseaseField);
panel.add(complicationsLabel);
panel.add(complicationsField);
panel.add(new JLabel());
panel.add(assignButton);
assignButton.addActionListener(e -> {
try {
int roomNumber = Integer.parseInt(roomField.getText());
int bedNumber = Integer.parseInt(bedField.getText());
String name = nameField.getText();
String disease = diseaseField.getText();
String complications = complicationsField.getText();
Patient patient = new Patient(roomNumber, bedNumber, name, disease, complications);
roomAssignments.put(roomNumber, patient);
JOptionPane.showMessageDialog(frame, "Patient assigned successfully!");
frame.dispose();
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid input. Please try again.");
}
});
frame.add(panel);
frame.setVisible(true);
}
private void showScheduleAppointmentScreen() {
JFrame frame = new JFrame("Schedule an Appointment");
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(7, 2, 10, 10));
panel.setBackground(new Color(245, 245, 245));
JLabel nameLabel = new JLabel("Patient Name:");
JTextField nameField = new JTextField();
JLabel dateLabel = new JLabel("Appointment Date:");
JTextField dateField = new JTextField();
JLabel timeLabel = new JLabel("Appointment Time:");
JTextField timeField = new JTextField();
JLabel doctorLabel = new JLabel("Doctor's Name:");
JTextField doctorField = new JTextField();
JLabel reasonLabel = new JLabel("Reason:");
JTextField reasonField = new JTextField();
JButton scheduleButton = new JButton("Schedule");
Font font = new Font("Arial", Font.PLAIN, 25);
nameLabel.setFont(font);
dateLabel.setFont(font);
timeLabel.setFont(font);
doctorLabel.setFont(font);
reasonLabel.setFont(font);
nameField.setFont(font);
dateField.setFont(font);
timeField.setFont(font);
doctorField.setFont(font);
reasonField.setFont(font);
scheduleButton.setFont(font);
panel.add(nameLabel);
panel.add(nameField);
panel.add(dateLabel);
panel.add(dateField);
panel.add(timeLabel);
panel.add(timeField);
panel.add(doctorLabel);
panel.add(doctorField);
panel.add(reasonLabel);
panel.add(reasonField);
panel.add(new JLabel());
panel.add(scheduleButton);
scheduleButton.addActionListener(e -> {
String name = nameField.getText();
String date = dateField.getText();
String time = timeField.getText();
String doctor = doctorField.getText();
String reason = reasonField.getText();
Appointment appointment = new Appointment(name, date, time, doctor, reason);
appointments.put(name, appointment);
JOptionPane.showMessageDialog(frame, "Appointment scheduled successfully!");
frame.dispose();
});
frame.add(panel);
frame.setVisible(true);
}
private void showViewDataScreen() {
JFrame frame = new JFrame("View Data");
frame.setSize(600, 500);
frame.setLocationRelativeTo(null);
JTextArea textArea = new JTextArea();
textArea.setEditable(false);
textArea.setFont(new Font("Arial", Font.PLAIN, 20));
StringBuilder data = new StringBuilder("Room Assignments:\n");
for (Patient patient : roomAssignments.values()) {
data.append(patient).append("\n");
}
data.append("\nAppointments:\n");
for (Appointment appointment : appointments.values()) {
data.append(appointment).append("\n");
}
textArea.setText(data.toString());
frame.add(new JScrollPane(textArea));
frame.setVisible(true);
}
}
class Patient {
private int roomNumber;
private int bedNumber;
private String name;
private String disease;
private String complications;
public Patient(int roomNumber, int bedNumber, String name, String disease, String complications) {
this.roomNumber = roomNumber;
this.bedNumber = bedNumber;
this.name = name;
this.disease = disease;
this.complications = complications;
}
@Override
public String toString() {
return String.format("Room %d, Bed %d: %s (Disease: %s, Complications: %s)",
roomNumber, bedNumber, name, disease, complications);
}
public String toFileFormat() {
return String.format("%d,%d,%s,%s,%s", roomNumber, bedNumber, name, disease, complications);
}
}
class Appointment {
private String patientName;
private String date;
private String time;
private String doctor;
private String reason;
public Appointment(String patientName, String date, String time, String doctor, String reason) {
this.patientName = patientName;
this.date = date;
this.time = time;
this.doctor = doctor;
this.reason = reason;
}
@Override
public String toString() {
return String.format("Patient: %s, Date: %s, Time: %s, Doctor: %s, Reason: %s",
patientName, date, time, doctor, reason);
}
public String toFileFormat() {
return String.format("%s,%s,%s,%s,%s", patientName, date, time, doctor, reason);
}
}