-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenu.java
564 lines (492 loc) · 26.4 KB
/
MainMenu.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
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
public class MainMenu extends JFrame {
private double calculateEstimatedPrice(String initialPoint, String finalDestination) {
return Math.random() * 100 + 20;
}
private boolean checkTaxiAvailability(String initialPoint, String finalDestination) {
return Math.random() > 0.5;
}
private double walletBalance;
private JLabel clockLabel;
private JLabel notificationLabel;
private JButton showNotificationsButton;
private JLabel walletLabel;
private ArrayList<Taxi> taxis;
private DefaultListModel<String> notificationsModel;
private JList<String> notificationList;
private JComboBox<String> taxiComboBox;
private JTable taxiTable;
private DefaultTableModel taxiTableModel;
private double currentFare;
// New Colors based on Midnight blue, Royal blue, Burgundy red, and White
private final Color BG_COLOR_DARK = new Color(25, 25, 112); // Midnight blue
private final Color BG_COLOR_LIGHT = new Color(70, 130, 180); // Light blue
private final Color PANEL_COLOR = new Color(12, 53, 120); // Royal blue
private final Color BUTTON_COLOR = Color.BLACK; // Button color always black
private final Color BUTTON_TEXT_COLOR = Color.BLACK; // Button description always black
private final Color TEXT_COLOR = Color.WHITE; // White text
private final Color ACCENT_COLOR = new Color(44, 130, 201); // Accent blue
private boolean isLightTheme = true;
public MainMenu(double initialBalance) {
this.walletBalance = initialBalance;
taxis = new ArrayList<>();
notificationsModel = new DefaultListModel<>();
initializeTaxis();
addSampleNewsNotifications();
setTitle("Taxi Service Dashboard");
setSize(1200, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Use Mac OS specific settings if available
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem saveMenuItem = new JMenuItem("Save");
JMenuItem exitMenuItem = new JMenuItem("Exit");
fileMenu.add(saveMenuItem);
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
JMenu editMenu = new JMenu("Edit");
JMenuItem themeMenuItem = new JMenuItem("Switch Theme");
editMenu.add(themeMenuItem);
menuBar.add(editMenu);
JMenu helpMenu = new JMenu("Help");
JMenuItem aboutMenuItem = new JMenuItem("About");
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
saveMenuItem.addActionListener(e -> saveTaxiData());
exitMenuItem.addActionListener(e -> System.exit(0));
themeMenuItem.addActionListener(e -> switchTheme());
aboutMenuItem.addActionListener(e -> JOptionPane.showMessageDialog(this, "Taxi Service Dashboard v2.0", "About", JOptionPane.INFORMATION_MESSAGE));
JPanel mainContainer = new JPanel(new BorderLayout());
mainContainer.setBackground(isLightTheme ? BG_COLOR_LIGHT : BG_COLOR_DARK);
JPanel headerPanel = new JPanel(new BorderLayout());
headerPanel.setPreferredSize(new Dimension(getWidth(), 80));
headerPanel.setBackground(PANEL_COLOR);
JLabel logoLabel = new JLabel("Taxi Service Dashboard", JLabel.LEFT);
logoLabel.setFont(new Font("Arial", Font.BOLD, 28));
logoLabel.setForeground(TEXT_COLOR);
headerPanel.add(logoLabel, BorderLayout.WEST);
clockLabel = new JLabel();
clockLabel.setFont(new Font("Arial", Font.BOLD, 24));
clockLabel.setForeground(TEXT_COLOR);
headerPanel.add(clockLabel, BorderLayout.EAST);
startClock();
JTextField searchField = new JTextField("Search...");
searchField.setPreferredSize(new Dimension(300, 30));
searchField.setBackground(PANEL_COLOR);
searchField.setForeground(TEXT_COLOR);
searchField.setBorder(BorderFactory.createLineBorder(ACCENT_COLOR));
JButton searchButton = new JButton("Search");
searchButton.setPreferredSize(new Dimension(100, 30));
searchButton.setBackground(BUTTON_COLOR);
searchButton.setForeground(BUTTON_TEXT_COLOR);
searchButton.setFocusPainted(false);
JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
searchPanel.setOpaque(false);
searchPanel.add(searchField);
searchPanel.add(searchButton);
headerPanel.add(searchPanel, BorderLayout.CENTER);
searchButton.addActionListener(e -> {
String searchQuery = searchField.getText().trim();
if (!searchQuery.isEmpty()) {
StringBuilder result = new StringBuilder();
for (Taxi taxi : taxis) {
if (taxi.getTaxiNumber().toLowerCase().contains(searchQuery.toLowerCase()) ||
searchQuery.equalsIgnoreCase(taxi.getStartTime()) ||
searchQuery.equalsIgnoreCase(taxi.getEndTime())) {
result.append("Taxi Number: ").append(taxi.getTaxiNumber())
.append(", Available Start Time: ").append(taxi.getStartTime())
.append(", Available End Time: ").append(taxi.getEndTime()).append("\n");
}
}
if (result.length() == 0) {
JOptionPane.showMessageDialog(this, "No taxis found for the given search.", "Search Result", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, result.toString(), "Search Result", JOptionPane.INFORMATION_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this, "Please enter a search term.", "Input Error", JOptionPane.ERROR_MESSAGE);
}
});
mainContainer.add(headerPanel, BorderLayout.NORTH);
JPanel sidebarPanel = new JPanel();
sidebarPanel.setLayout(new BoxLayout(sidebarPanel, BoxLayout.Y_AXIS));
sidebarPanel.setBackground(isLightTheme ? BG_COLOR_LIGHT : BG_COLOR_DARK);
sidebarPanel.setPreferredSize(new Dimension(250, getHeight()));
JButton bookTaxiButton = createModernSidebarButton("Book a Taxi", BUTTON_COLOR);
JButton nearbyTaxiButton = createModernSidebarButton("See Nearby Taxis", BUTTON_COLOR);
JButton taxiRoutesButton = createModernSidebarButton("View Taxi Routes", BUTTON_COLOR);
JButton taxiScheduleButton = createModernSidebarButton("Taxi Schedule", BUTTON_COLOR);
JButton themeSwitcher = createModernSidebarButton("Switch Theme", BUTTON_COLOR);
sidebarPanel.add(Box.createRigidArea(new Dimension(0, 20)));
sidebarPanel.add(bookTaxiButton);
sidebarPanel.add(Box.createRigidArea(new Dimension(0, 10)));
sidebarPanel.add(nearbyTaxiButton);
sidebarPanel.add(Box.createRigidArea(new Dimension(0, 10)));
sidebarPanel.add(taxiRoutesButton);
sidebarPanel.add(Box.createRigidArea(new Dimension(0, 10)));
sidebarPanel.add(taxiScheduleButton);
sidebarPanel.add(Box.createRigidArea(new Dimension(0, 10)));
sidebarPanel.add(themeSwitcher);
mainContainer.add(sidebarPanel, BorderLayout.WEST);
JPanel contentPanel = new JPanel(new CardLayout());
contentPanel.setOpaque(false);
JPanel walletPanel = new JPanel(new GridBagLayout());
walletPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
walletPanel.setOpaque(false);
walletLabel = new JLabel(String.format("Wallet Balance: R%.2f", walletBalance), SwingConstants.CENTER);
walletLabel.setFont(new Font("Arial", Font.BOLD, 28));
walletLabel.setForeground(TEXT_COLOR);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 10, 10);
JPanel inputPanel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(PANEL_COLOR);
g.fillRect(0, 0, getWidth(), getHeight());
}
};
inputPanel.setLayout(new GridLayout(3, 2, 20, 20));
inputPanel.setOpaque(false);
JLabel initialPointLabel = new JLabel("Initial Point:");
initialPointLabel.setFont(new Font("Arial", Font.BOLD, 20));
initialPointLabel.setForeground(TEXT_COLOR);
JTextField initialPointField = new JTextField();
initialPointField.setBackground(PANEL_COLOR);
initialPointField.setForeground(TEXT_COLOR);
initialPointField.setBorder(BorderFactory.createLineBorder(ACCENT_COLOR));
JLabel finalDestinationLabel = new JLabel("Final Destination:");
finalDestinationLabel.setFont(new Font("Arial", Font.BOLD, 20));
finalDestinationLabel.setForeground(TEXT_COLOR);
JTextField finalDestinationField = new JTextField();
finalDestinationField.setBackground(PANEL_COLOR);
finalDestinationField.setForeground(TEXT_COLOR);
finalDestinationField.setBorder(BorderFactory.createLineBorder(ACCENT_COLOR));
JLabel taxiSelectionLabel = new JLabel("Select Taxi:");
taxiSelectionLabel.setFont(new Font("Arial", Font.BOLD, 20));
taxiSelectionLabel.setForeground(TEXT_COLOR);
taxiComboBox = new JComboBox<>(new String[]{"Standard Taxi", "Luxury Taxi", "Minibus"});
taxiComboBox.setBackground(PANEL_COLOR);
taxiComboBox.setForeground(TEXT_COLOR);
inputPanel.add(initialPointLabel);
inputPanel.add(initialPointField);
inputPanel.add(finalDestinationLabel);
inputPanel.add(finalDestinationField);
inputPanel.add(taxiSelectionLabel);
inputPanel.add(taxiComboBox);
gbc.gridx = 0;
gbc.gridy = 0;
walletPanel.add(walletLabel, gbc);
gbc.gridy = 1;
walletPanel.add(inputPanel, gbc);
gbc.gridy = 2;
JPanel walletButtonPanel = new JPanel(new GridLayout(1, 3, 10, 10));
walletButtonPanel.setOpaque(false);
JButton addMoneyButton = createModernSidebarButton("Add Money", BUTTON_COLOR);
JButton withdrawMoneyButton = createModernSidebarButton("Pay", BUTTON_COLOR);
JButton showMapButton = createModernSidebarButton("Show Map", BUTTON_COLOR);
walletButtonPanel.add(addMoneyButton);
walletButtonPanel.add(withdrawMoneyButton);
walletButtonPanel.add(showMapButton);
walletPanel.add(walletButtonPanel, gbc);
gbc.gridy = 3;
JButton calculateButton = createModernSidebarButton("Calculate Fare & Availability", BUTTON_COLOR);
walletPanel.add(calculateButton, gbc);
gbc.gridy = 4;
JLabel estimatedPriceLabel = new JLabel("Estimated Price: N/A");
estimatedPriceLabel.setFont(new Font("Arial", Font.BOLD, 20));
estimatedPriceLabel.setForeground(TEXT_COLOR);
walletPanel.add(estimatedPriceLabel, gbc);
gbc.gridy = 5;
JLabel taxiAvailabilityLabel = new JLabel("Taxi Availability: N/A");
taxiAvailabilityLabel.setFont(new Font("Arial", Font.BOLD, 20));
taxiAvailabilityLabel.setForeground(TEXT_COLOR);
walletPanel.add(taxiAvailabilityLabel, gbc);
gbc.gridy = 6;
taxiTableModel = new DefaultTableModel(new String[]{"Taxi Number", "Available Start Time", "Available End Time"}, 0);
taxiTable = new JTable(taxiTableModel);
taxiTable.setFillsViewportHeight(true);
taxiTable.setFont(new Font("Arial", Font.PLAIN, 14));
taxiTable.setRowHeight(30);
JTableHeader header = taxiTable.getTableHeader();
header.setFont(new Font("Arial", Font.BOLD, 16));
header.setBackground(ACCENT_COLOR);
header.setForeground(TEXT_COLOR);
JScrollPane tableScrollPane = new JScrollPane(taxiTable);
tableScrollPane.setPreferredSize(new Dimension(600, 200));
walletPanel.add(tableScrollPane, gbc);
contentPanel.add(walletPanel, "walletPanel");
mainContainer.add(contentPanel, BorderLayout.CENTER);
JPanel notificationPanel = new JPanel(new BorderLayout());
notificationPanel.setPreferredSize(new Dimension(300, 300));
notificationPanel.setBackground(PANEL_COLOR);
notificationLabel = new JLabel("Notifications", JLabel.LEFT);
notificationLabel.setFont(new Font("Arial", Font.BOLD, 28));
notificationLabel.setForeground(TEXT_COLOR);
notificationPanel.add(notificationLabel, BorderLayout.NORTH);
notificationList = new JList<>(notificationsModel);
notificationList.setBackground(PANEL_COLOR);
notificationList.setForeground(TEXT_COLOR);
notificationList.setFont(new Font("Arial", Font.PLAIN, 16));
JScrollPane notificationScrollPane = new JScrollPane(notificationList);
notificationPanel.add(notificationScrollPane, BorderLayout.CENTER);
JButton hideNotificationsButton = new JButton("Hide Notifications");
hideNotificationsButton.setFont(new Font("Arial", Font.BOLD, 16));
hideNotificationsButton.setBackground(BUTTON_COLOR);
hideNotificationsButton.setForeground(BUTTON_TEXT_COLOR);
hideNotificationsButton.setFocusPainted(false);
hideNotificationsButton.addActionListener(e -> {
notificationPanel.setVisible(false);
showNotificationsButton.setVisible(true);
});
showNotificationsButton = new JButton("Show Notifications");
showNotificationsButton.setFont(new Font("Arial", Font.BOLD, 16));
showNotificationsButton.setBackground(BUTTON_COLOR);
showNotificationsButton.setForeground(BUTTON_TEXT_COLOR);
showNotificationsButton.setFocusPainted(false);
showNotificationsButton.setVisible(false);
showNotificationsButton.addActionListener(e -> {
notificationPanel.setVisible(true);
showNotificationsButton.setVisible(false);
});
mainContainer.add(showNotificationsButton, BorderLayout.SOUTH);
notificationPanel.add(hideNotificationsButton, BorderLayout.SOUTH);
mainContainer.add(notificationPanel, BorderLayout.EAST);
setContentPane(mainContainer);
setVisible(true);
bookTaxiButton.addActionListener(e -> {
String initialPoint = JOptionPane.showInputDialog(this, "Enter initial point:");
String finalDestination = JOptionPane.showInputDialog(this, "Enter final destination:");
if (initialPoint != null && finalDestination != null && !initialPoint.isEmpty() && !finalDestination.isEmpty()) {
currentFare = calculateEstimatedPrice(initialPoint, finalDestination);
boolean isTaxiAvailable = checkTaxiAvailability(initialPoint, finalDestination);
String message = "Estimated Price: R" + String.format("%.2f", currentFare) + "\nTaxi Availability: " + (isTaxiAvailable ? "Available" : "Not Available");
JOptionPane.showMessageDialog(this, message, "Booking Result", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "Please enter both initial and final destinations.", "Input Error", JOptionPane.ERROR_MESSAGE);
}
});
nearbyTaxiButton.addActionListener(e -> JOptionPane.showMessageDialog(this, "See Nearby Taxis..."));
taxiRoutesButton.addActionListener(e -> {
String initialPoint = initialPointField.getText();
String finalDestination = finalDestinationField.getText();
if (!initialPoint.isEmpty() && !finalDestination.isEmpty()) {
try {
String encodedInitialPoint = URLEncoder.encode(initialPoint, StandardCharsets.UTF_8.toString());
String encodedFinalDestination = URLEncoder.encode(finalDestination, StandardCharsets.UTF_8.toString());
String googleMapsUrl = "https://www.google.com/maps/dir/?api=1&origin=" + encodedInitialPoint + "&destination=" + encodedFinalDestination;
Desktop.getDesktop().browse(new java.net.URI(googleMapsUrl));
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Error while opening Google Maps: " + ex.getMessage(), "Map Error", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this, "Please enter both initial and final destinations.", "Input Error", JOptionPane.ERROR_MESSAGE);
}
});
taxiScheduleButton.addActionListener(e -> showTaxiSchedule());
themeSwitcher.addActionListener(e -> switchTheme());
addMoneyButton.addActionListener(e -> adjustWalletBalance(50.0));
withdrawMoneyButton.addActionListener(e -> {
if (walletBalance >= currentFare) {
adjustWalletBalance(-currentFare);
JOptionPane.showMessageDialog(this, "Payment of R" + String.format("%.2f", currentFare) + " successful.", "Payment Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "Insufficient balance. Please add more money to your wallet.", "Payment Error", JOptionPane.ERROR_MESSAGE);
}
});
calculateButton.addActionListener(e -> {
String initialPoint = initialPointField.getText();
String finalDestination = finalDestinationField.getText();
String taxiType = (String) taxiComboBox.getSelectedItem();
if (!initialPoint.isEmpty() && !finalDestination.isEmpty()) {
currentFare = calculateEstimatedPrice(initialPoint, finalDestination);
boolean isTaxiAvailable = checkTaxiAvailability(initialPoint, finalDestination);
estimatedPriceLabel.setText("Estimated Price: R" + String.format("%.2f", currentFare) + " (" + taxiType + ")");
taxiAvailabilityLabel.setText("Taxi Availability: " + (isTaxiAvailable ? "Available" : "Not Available"));
} else {
JOptionPane.showMessageDialog(this, "Please enter both initial and final destinations.", "Input Error", JOptionPane.ERROR_MESSAGE);
}
});
showMapButton.addActionListener(e -> {
String initialPoint = initialPointField.getText();
String finalDestination = finalDestinationField.getText();
if (!initialPoint.isEmpty() && !finalDestination.isEmpty()) {
try {
String encodedInitialPoint = URLEncoder.encode(initialPoint, StandardCharsets.UTF_8.toString());
String encodedFinalDestination = URLEncoder.encode(finalDestination, StandardCharsets.UTF_8.toString());
String googleMapsUrl = "https://www.google.com/maps/dir/?api=1&origin=" + encodedInitialPoint + "&destination=" + encodedFinalDestination;
Desktop.getDesktop().browse(new java.net.URI(googleMapsUrl));
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Error while opening Google Maps: " + ex.getMessage(), "Map Error", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this, "Please enter both initial and final destinations.", "Input Error", JOptionPane.ERROR_MESSAGE);
}
});
loadTaxisIntoTable();
}
private void startClock() {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
clockLabel.setText(sdf.format(new Date()));
}
}, 0, 1000);
}
private JButton createModernSidebarButton(String text, Color color) {
JButton button = new JButton(text);
button.setFont(new Font("Arial", Font.BOLD, 18));
button.setAlignmentX(Component.LEFT_ALIGNMENT);
button.setMaximumSize(new Dimension(200, 50));
button.setBackground(color);
button.setForeground(BUTTON_TEXT_COLOR);
button.setFocusPainted(false);
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
return button;
}
private void showTaxiSchedule() {
if (taxis.isEmpty()) {
JOptionPane.showMessageDialog(this, "No taxi schedule available.", "No Data", JOptionPane.INFORMATION_MESSAGE);
return;
}
loadTaxisIntoTable();
}
private void switchTheme() {
isLightTheme = !isLightTheme;
Color panelBackground = isLightTheme ? BG_COLOR_LIGHT : BG_COLOR_DARK;
Color labelForeground = TEXT_COLOR;
Color buttonBackground = BUTTON_COLOR;
Color buttonForeground = BUTTON_TEXT_COLOR;
getContentPane().setBackground(panelBackground);
for (Component component : getContentPane().getComponents()) {
updateComponentTheme(component, panelBackground, labelForeground, buttonBackground, buttonForeground);
}
SwingUtilities.updateComponentTreeUI(this);
}
private void updateComponentTheme(Component component, Color panelBackground, Color labelForeground, Color buttonBackground, Color buttonForeground) {
if (component instanceof JPanel) {
component.setBackground(panelBackground);
for (Component child : ((JPanel) component).getComponents()) {
updateComponentTheme(child, panelBackground, labelForeground, buttonBackground, buttonForeground);
}
} else if (component instanceof JLabel) {
component.setForeground(labelForeground);
} else if (component instanceof JButton) {
component.setBackground(buttonBackground);
component.setForeground(buttonForeground);
} else if (component instanceof JTextField) {
component.setBackground(PANEL_COLOR);
component.setForeground(labelForeground);
}
}
private void adjustWalletBalance(double amount) {
walletBalance += amount;
walletLabel.setText(String.format("Wallet Balance: R%.2f", walletBalance));
JOptionPane.showMessageDialog(this, String.format("Wallet updated. New Balance: R%.2f", walletBalance), "Wallet Update", JOptionPane.INFORMATION_MESSAGE);
}
private void initializeTaxis() {
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("taxis.ser"))) {
taxis = (ArrayList<Taxi>) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
taxis = new ArrayList<>();
JOptionPane.showMessageDialog(this, "Failed to load taxi data. Starting with an empty list.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
private void saveTaxiData() {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("taxis.ser"))) {
oos.writeObject(taxis);
JOptionPane.showMessageDialog(this, "Taxi data saved successfully.", "Save Data", JOptionPane.INFORMATION_MESSAGE);
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Failed to save taxi data.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
private void loadTaxisIntoTable() {
taxiTableModel.setRowCount(0);
for (Taxi taxi : taxis) {
taxiTableModel.addRow(new Object[]{taxi.getTaxiNumber(), taxi.getStartTime(), taxi.getEndTime()});
}
}
private void addSampleNewsNotifications() {
notificationsModel.addElement("Welcome to the Taxi Service App!");
notificationsModel.addElement("Maintenance on Sunday.");
notificationsModel.addElement("New routes to Pretoria.");
notificationsModel.addElement("Holiday discounts available.");
notificationsModel.addElement("Taxi availability increased on weekends.");
notificationsModel.addElement("Introducing Luxury Taxi service.");
notificationsModel.addElement("Safety measures updated.");
notificationsModel.addElement("New payment options available.");
notificationsModel.addElement("Service extended to new areas.");
notificationsModel.addElement("Maintenance scheduled for next week.");
notificationsModel.addElement("Special fares during rush hours.");
notificationsModel.addElement("Driver training sessions ongoing.");
notificationsModel.addElement("Customer satisfaction survey available.");
notificationsModel.addElement("New partnership with local businesses.");
notificationsModel.addElement("Emergency contact feature added.");
notificationsModel.addElement("Real-time location sharing available.");
notificationsModel.addElement("New app update released.");
notificationsModel.addElement("Feedback requested for recent rides.");
notificationsModel.addElement("Referral rewards now available.");
notificationsModel.addElement("24/7 customer support launched.");
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new MainMenu(100.0));
}
}