-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomerStatusPanel.java
59 lines (47 loc) · 2.03 KB
/
CustomerStatusPanel.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
package flightscheduleryjw5018.gui;
import flightscheduleryjw5018.data.Booking;
import flightscheduleryjw5018.services.SchedulingService;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.util.Collection;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
public class CustomerStatusPanel extends JPanel {
private SchedulingService schedulingService;
private final JTextField customer = new JTextField("", 20);
private final JTable flightStatus = new JTable();
public CustomerStatusPanel() {
}
public void init() {
setLayout(new BorderLayout());
JPanel topPanel = new JPanel();
topPanel.add(new JLabel("Customer"));
topPanel.add(customer);
JButton getStatusButton = new JButton("Get Status");
getStatusButton.addActionListener((ActionEvent e) -> {
String customerName = customer.getText();
Collection<Booking> bookings = schedulingService.getCustomerStatus(customerName);
if (bookings != null) {
DefaultTableModel model = (DefaultTableModel) flightStatus.getModel();
// Clear the table
model.setRowCount(0);
// Add new rows
for (Booking booking : bookings) {
model.addRow(new Object[]{booking.getFlight(), booking.getDate(), booking.isBooked() ? "booked" : "waitlisted"});
}
}
});
topPanel.add(getStatusButton);
add(topPanel, BorderLayout.NORTH);
flightStatus.setModel(new DefaultTableModel(new Object[]{"Flight", "Date", "Status"}, 0));
add(new JScrollPane(flightStatus), BorderLayout.CENTER);
}
public void setSchedulingService(SchedulingService schedulingService) {
this.schedulingService = schedulingService;
}
}