-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRestaurant.java
More file actions
100 lines (89 loc) · 3.46 KB
/
Restaurant.java
File metadata and controls
100 lines (89 loc) · 3.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
/**
* Restaurant GUI that displays the list of incoming orders for the currently logged in restaurant.
* The restaurant can select an order and mark it as complete.
*
* There is a button to logout and return to the login screen.
*
*/
public class Restaurant extends JDialog implements ActionListener {
private Container c;
private JLabel title;
private JList<String> ordersList;
private DefaultListModel<String> listModel;
private JButton completeButton;
private JButton logoutButton;
private String[] orders;
private String[] orderStatuses;
private String[] orderTotals;
private String[] orderTimes;
private String[] orderCustomers;
public Restaurant() {
setTitle("Restaurant");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
c = getContentPane();
c.setLayout(null);
setSize(1000, 800);
title = new JLabel(Client.name + "'s Incoming Orders");
listModel = new DefaultListModel<String>();
ordersList = new JList<String>(listModel);
completeButton = new JButton("Mark as Complete");
completeButton.addActionListener(this);
logoutButton = new JButton("Logout");
logoutButton.addActionListener(this);
title.setFont(new Font("Arial", Font.PLAIN, 30));
title.setSize(500, 30);
title.setLocation(250, 30);
ordersList.setBounds(100, 100, 800, 500);
completeButton.setBounds(100, 650, 200, 50);
logoutButton.setBounds(700, 650, 200, 50);
c.add(title);
c.add(ordersList);
c.add(completeButton);
c.add(logoutButton);
// try to get orders from server every 5 seconds
Timer timer = new Timer(5000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// getOrders();
// updateOrdersList();
System.out.println("Restaurant: Sending list|restaurant to server");
}
});
timer.start();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == completeButton) {
// send "complete|orderID" to server
try {
System.out.println("Restaurant: Sending complete|orderID to server");
Client.os.write("complete|orderID".getBytes());
// get server response
byte[] response = new byte[1024];
Client.is.read(response);
String res = new String(response).replace("\n", "").replace("\r", "").replace("\"", "").replace("\0", "");
System.out.println("Restaurant: Server response: " + res);
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (e.getSource() == logoutButton) {
// send "logout" to server
try {
System.out.println("RestaurantListForm: Sending logout to server");
Client.os.write("logout".getBytes());
this.dispose();
Client.landingForm = new LandingForm();
Client.landingForm.setVisible(true);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
public static void main(String[] args) {
Restaurant restaurant = new Restaurant();
restaurant.setVisible(true);
}
}