-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.java
More file actions
117 lines (94 loc) · 3.27 KB
/
Copy pathMenu.java
File metadata and controls
117 lines (94 loc) · 3.27 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
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
// Custom JPanel to draw a background image
class ImagePanel extends JPanel {
private Image backgroundImage;
public ImagePanel(String imagePath) {
try {
backgroundImage = ImageIO.read(new File(imagePath));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (backgroundImage != null) {
g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
}
}
}
public class Menu {
private JFrame frame;
private JButton rentButton, returnButton, listButton, logoutButton;
private JPanel panel;
private Logic logic;
private LoginSignupApp app;
private Image backgroundImage;
public Menu(JFrame frame, Logic logic, LoginSignupApp app) {
this.frame = frame;
this.logic = logic;
this.app = app;
initComponents();
}
private void initComponents() {
String imagePath = "bg/Menupic.png";
try {
backgroundImage = ImageIO.read(new File("bg/Loginpic.png"));
} catch (Exception e) {
e.printStackTrace();
}
// Create the panel with a background image
panel = new ImagePanel(imagePath);
panel.setLayout(new GridLayout(4, 2, 5, 7));
Border border = BorderFactory.createLineBorder(Color.GREEN, 3);
panel.setBorder(border);
JLabel label = new JLabel("");
panel.add(label);
JLabel blank = new JLabel();
panel.add(blank);
rentButton = new JButton("Rent a laptop");
rentButton.addActionListener(e -> handleRentButtonClick());
panel.add(rentButton);
returnButton = new JButton("Return a laptop");
returnButton.addActionListener(e -> handleReturnButtonClick());
panel.add(returnButton);
listButton = new JButton("Check available laptops");
listButton.addActionListener(e -> handleListButtonClick());
panel.add(listButton);
logoutButton = new JButton("Logout");
logoutButton.addActionListener(e -> handleLogoutButtonClick());
panel.add(logoutButton);
frame.add(panel);
}
private void handleRentButtonClick() {
logic.createTextFieldWindow("Rent a Laptop", "Student ID", "Username", "Laptop ID");
}
private void handleReturnButtonClick() {
logic.returnLaptop();
}
private void handleListButtonClick() {
logic.displayAvailableLaptops();
}
public JButton getRentButton() {
return rentButton;
}
public JButton getReturnButton() {
return returnButton;
}
public JButton getListButton() {
return listButton;
}
public void handleLogoutButtonClick() {
app.showAdminPanel(false);
frame.setVisible(false); // Hide the GUI
LoginSignupApp newAppInstance = new LoginSignupApp(); // Create a new instance of LoginSignupApp
newAppInstance.setVisible(true); // Show the new login/signup app window
}
}