|
1 | 1 | package Entity.InterfaceGui;
|
2 | 2 |
|
3 |
| -import java.awt.BorderLayout; |
4 |
| -import java.awt.Color; |
5 |
| -import java.awt.Font; |
6 |
| -import java.awt.GridLayout; |
7 |
| - |
8 |
| -import javax.swing.JButton; |
9 |
| -import javax.swing.JFrame; |
10 |
| -import javax.swing.JPanel; |
| 3 | +import java.awt.*; |
| 4 | +import javax.swing.*; |
11 | 5 |
|
12 | 6 | public class ProductMain extends JFrame {
|
13 | 7 | private JButton addPButton;
|
14 |
| - private JButton editPButton;; |
| 8 | + private JButton editPButton; |
15 | 9 | private JButton deletePButton;
|
16 | 10 |
|
17 |
| - ProductMain() { |
| 11 | + public ProductMain() { |
18 | 12 | setTitle("Manage Product");
|
19 | 13 | setSize(500, 300);
|
20 |
| - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 14 | + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
21 | 15 | setLocationRelativeTo(null);
|
| 16 | + setLayout(new BorderLayout()); |
22 | 17 |
|
23 |
| - JPanel panel = new JPanel(new BorderLayout()); |
24 | 18 | JPanel centerPanel = new JPanel(new GridLayout(3, 1, 10, 10));
|
25 | 19 | centerPanel.setBackground(new Color(240, 240, 240));
|
26 | 20 |
|
27 | 21 | addPButton = new JButton("Add Product");
|
28 | 22 | addPButton.setFont(new Font("Arial", Font.PLAIN, 14));
|
29 |
| - addPButton.addActionListener(e -> { |
30 |
| - new ProductInputGUI(); // Open Manage Product GUI |
31 |
| - dispose(); |
32 |
| - }); |
| 23 | + addPButton.addActionListener(e -> openWindow(new ProductInputGUI())); |
33 | 24 |
|
34 | 25 | editPButton = new JButton("Edit Product");
|
35 | 26 | editPButton.setFont(new Font("Arial", Font.PLAIN, 14));
|
36 |
| - editPButton.addActionListener(e -> { |
37 |
| - // new ProductEditGUI(); // Open Manage Product GUI |
38 |
| - dispose(); |
39 |
| - }); |
| 27 | + editPButton.addActionListener(e -> openWindow(new ProductEditGUI())); |
| 28 | + |
| 29 | + deletePButton = new JButton("Delete Product"); |
| 30 | + deletePButton.setFont(new Font("Arial", Font.PLAIN, 14)); |
| 31 | + deletePButton.addActionListener(e -> openWindow(new ProductDeleteGUI())); |
40 | 32 |
|
41 |
| - panel.add(centerPanel, BorderLayout.CENTER); |
42 |
| - add(panel); |
43 | 33 | centerPanel.add(addPButton);
|
| 34 | + centerPanel.add(editPButton); |
| 35 | + centerPanel.add(deletePButton); |
| 36 | + |
| 37 | + add(centerPanel, BorderLayout.CENTER); |
44 | 38 | setVisible(true);
|
45 | 39 | }
|
| 40 | + |
| 41 | + private void openWindow(JFrame frame) { |
| 42 | + frame.setVisible(true); |
| 43 | + dispose(); // Closes the current window when a new one opens |
| 44 | + } |
| 45 | + |
46 | 46 | public static void main(String[] args) {
|
47 |
| - new ProductMain(); // Test with "admin" or "user" |
| 47 | + SwingUtilities.invokeLater(ProductMain::new); |
48 | 48 | }
|
49 | 49 | }
|
0 commit comments