-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoodOrderingSystem.java
More file actions
124 lines (105 loc) · 4.16 KB
/
Copy pathFoodOrderingSystem.java
File metadata and controls
124 lines (105 loc) · 4.16 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FoodOrderingSystem extends JFrame {
private JButton customerButton, restaurantButton, orderButton, exitButton;
public FoodOrderingSystem() {
setTitle("Food Ordering System");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridBagLayout());
// Create title label
JLabel titleLabel = new JLabel("Food Ordering System", SwingConstants.CENTER);
titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
titleLabel.setForeground(new Color(51, 102, 153));
// Create buttons
customerButton = new JButton("Manage Customers");
restaurantButton = new JButton("Manage Restaurants & Menu");
orderButton = new JButton("Place Orders");
exitButton = new JButton("Exit");
// Style buttons
Dimension buttonSize = new Dimension(250, 40);
Font buttonFont = new Font("Arial", Font.PLAIN, 14);
customerButton.setPreferredSize(buttonSize);
customerButton.setFont(buttonFont);
restaurantButton.setPreferredSize(buttonSize);
restaurantButton.setFont(buttonFont);
orderButton.setPreferredSize(buttonSize);
orderButton.setFont(buttonFont);
exitButton.setPreferredSize(buttonSize);
exitButton.setFont(buttonFont);
exitButton.setBackground(new Color(220, 53, 69));
exitButton.setForeground(Color.WHITE);
// Layout components
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);
gbc.gridx = 0; gbc.gridy = 0;
add(titleLabel, gbc);
gbc.gridy = 1;
add(customerButton, gbc);
gbc.gridy = 2;
add(restaurantButton, gbc);
gbc.gridy = 3;
add(orderButton, gbc);
gbc.gridy = 4;
add(exitButton, gbc);
// Add event listeners
customerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new CustomerManager().setVisible(true);
}
});
restaurantButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new RestaurantManager().setVisible(true);
}
});
orderButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new OrderManager().setVisible(true);
}
});
exitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int choice = JOptionPane.showConfirmDialog(
FoodOrderingSystem.this,
"Are you sure you want to exit?",
"Confirm Exit",
JOptionPane.YES_NO_OPTION
);
if (choice == JOptionPane.YES_OPTION) {
DatabaseConnection.closeConnection();
System.exit(0);
}
}
});
}
public static void main(String[] args) {
// Set look and feel
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
// Test database connection
if (DatabaseConnection.getConnection() == null) {
JOptionPane.showMessageDialog(null,
"Failed to connect to database! Please check your connection settings.",
"Database Error",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new FoodOrderingSystem().setVisible(true);
}
});
}
}