-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuideProfilePage.java
More file actions
139 lines (112 loc) · 5.38 KB
/
Copy pathGuideProfilePage.java
File metadata and controls
139 lines (112 loc) · 5.38 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import javax.swing.*;
import java.awt.*;
public class GuideProfilePage extends JPanel {
private String username;
private MainFrame mainFrame;
public GuideProfilePage(MainFrame mainFrame, String[] userInfo) {
this.mainFrame = mainFrame;
this.username = userInfo[3]; // Assuming username is the 4th field (index 3)
setLayout(new BorderLayout());
// Set the background image
ImageIcon backgroundImageIcon = new ImageIcon("profile-bg.jpg"); // Replace with your image file
Image backgroundImage = backgroundImageIcon.getImage();
BackgroundPanel backgroundPanel = new BackgroundPanel(backgroundImage);
// Create a panel to hold the profile information
JPanel profilePanel = new JPanel();
profilePanel.setBackground(new Color(255, 255, 224, 200)); // Light yellow with transparency
profilePanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 20, 10, 20);
gbc.anchor = GridBagConstraints.CENTER;
// Title Label
JLabel titleLabel = new JLabel("Guide Dashboard", SwingConstants.CENTER);
titleLabel.setFont(new Font("Arial", Font.BOLD, 32));
titleLabel.setForeground(Color.BLACK); // Set text color to black
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
profilePanel.add(titleLabel, gbc);
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
// Display user information
gbc.gridy++;
addLabelAndValue(profilePanel, gbc, "Name:", userInfo[0]);
gbc.gridy++;
addLabelAndValue(profilePanel, gbc, "Phone Number:", userInfo[1]);
gbc.gridy++;
addLabelAndValue(profilePanel, gbc, "Email:", userInfo[2]);
gbc.gridy++;
addLabelAndValue(profilePanel, gbc, "Username:", userInfo[3]);
gbc.gridy++;
addLabelAndValue(profilePanel, gbc, "Address:", userInfo[5]); // Adjust index if necessary
// Buttons Panel
gbc.gridy++;
gbc.gridx = 0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.CENTER;
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
buttonPanel.setOpaque(false);
JButton changePasswordButton = new JButton("Change Password");
styleButton(changePasswordButton);
changePasswordButton.addActionListener(e -> mainFrame.showChangePasswordPage(this.username, "GuidesData.txt", "Guide"));
buttonPanel.add(changePasswordButton);
JButton seeBookingsButton = new JButton("See Booking by Travelers");
styleButton(seeBookingsButton);
seeBookingsButton.addActionListener(e -> mainFrame.showSeeBookingGuidePage(this.username));
buttonPanel.add(seeBookingsButton);
JButton logoutButton = new JButton("Log Out");
styleButton(logoutButton);
logoutButton.addActionListener(e -> mainFrame.showPage("LoginPage"));
buttonPanel.add(logoutButton);
profilePanel.add(buttonPanel, gbc);
// Add profilePanel to backgroundPanel
backgroundPanel.add(profilePanel);
// Add backgroundPanel to the main panel
add(backgroundPanel, BorderLayout.CENTER);
}
private void addLabelAndValue(JPanel panel, GridBagConstraints gbc, String labelText, String valueText) {
JLabel label = new JLabel(labelText);
label.setFont(new Font("Arial", Font.BOLD, 18));
label.setForeground(Color.BLACK); // Set text color to black
gbc.gridx = 0;
panel.add(label, gbc);
JLabel value = new JLabel(valueText);
value.setFont(new Font("Arial", Font.PLAIN, 18));
value.setForeground(Color.BLACK); // Set text color to black
gbc.gridx = 1;
panel.add(value, gbc);
}
private void styleButton(JButton button) {
button.setFont(new Font("Arial", Font.BOLD, 16));
button.setForeground(Color.WHITE);
button.setBackground(new Color(64, 64, 64)); // Dark gray color
button.setFocusPainted(false);
button.setBorderPainted(false);
button.setOpaque(true);
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
// Add mouse hover effect
button.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
button.setBackground(new Color(255, 204, 0)); // Yellow color on hover
}
public void mouseExited(java.awt.event.MouseEvent evt) {
button.setBackground(new Color(64, 64, 64)); // Original color
}
});
}
// Custom JPanel to draw the background image
class BackgroundPanel extends JPanel {
private Image backgroundImage;
public BackgroundPanel(Image backgroundImage) {
this.backgroundImage = backgroundImage;
setLayout(new GridBagLayout()); // Center the profile panel
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Draw the background image scaled to fit the panel
g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
}
}
}