-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParkingGUI.java
102 lines (78 loc) · 3.31 KB
/
ParkingGUI.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
package park;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ParkingGUI extends JFrame implements ActionListener {
// GUI components
protected JLabel labelPlate, labelLot, labelAvailable;
protected JTextField fieldPlate;
protected JComboBox<Integer> comboLot;
protected JButton buttonSubmit;
public ParkingGUI() {
// Set up the frame
setTitle("Parking");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create the components
labelPlate = new JLabel("License Plate Number:");
labelLot = new JLabel("Parking Lot Number:");
labelAvailable = new JLabel("Parking spot available.");
fieldPlate = new JTextField(10);
Integer[] lots = {1, 2}; // Replace with actual lot numbers
comboLot = new JComboBox<>(lots);
buttonSubmit = new JButton("Submit");
buttonSubmit.addActionListener(this);
// Create the layout
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 2));
panel.add(labelPlate);
panel.add(fieldPlate);
panel.add(labelLot);
panel.add(comboLot);
panel.add(labelAvailable);
panel.add(buttonSubmit);
// Add the panel to the frame
add(panel);
// Make the frame visible
setVisible(true);
}
// Handle button click events
public void actionPerformed(ActionEvent e) {
if (e.getSource() == buttonSubmit) {
// Get the information from the GUI
/*
Req8: To book a parking space, clients need to provide a valid licence plate number. A client can edit or
cancel her/his bookings before the starting time of a booking.
* **/
String plate = fieldPlate.getText();
int lot = (int) comboLot.getSelectedItem();
// Check if the parking spot is available
boolean available = checkAvailability(plate, lot);
// OBSERVER Design Pattern Here
SuperManager superManager = new SuperManager();
ManagementTeam managementTeam = new ManagementTeam(superManager);
for(int i = 0; i < 5; i++) {
managementTeam.AutoAccountGeneration();
}
for(int j = 0; j < 100; j++) {
managementTeam.addParking();
}
// Update the label to display the availability
if (available) {
labelAvailable.setText("Parking spot available.");
}
// Update the label to display the availability
if (available) {
labelAvailable.setText("Parking spot available.");
Parkingcharges park = new Parkingcharges();
dispose();
}
dispose();
}
}
// Replace this method with actual availability checking code
protected boolean checkAvailability(String plate, int lot) {
// Always returns true for demonstration purposes
return true;
}
}