-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionPage.java
More file actions
118 lines (101 loc) · 5.11 KB
/
Copy pathSelectionPage.java
File metadata and controls
118 lines (101 loc) · 5.11 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
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class SelectionPage extends JPanel {
public SelectionPage(MainFrame mainFrame) {
setLayout(new BorderLayout());
// Set the background image
ImageIcon backgroundImageIcon = new ImageIcon("travel.jpg"); // Replace with your image file
Image backgroundImage = backgroundImageIcon.getImage();
BackgroundPanel backgroundPanel = new BackgroundPanel(backgroundImage);
backgroundPanel.setLayout(new GridBagLayout()); // To center the contentPanel
// Create a panel to hold the text and buttons
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.setOpaque(false); // Make it transparent to show background image
// Add some text (header and description)
JLabel headerLabel = new JLabel("Welcome to our Travel App!");
headerLabel.setFont(new Font("Arial", Font.BOLD, 28));
headerLabel.setForeground(Color.WHITE);
headerLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
JTextArea descriptionText = new JTextArea(
"Explore new destinations and connect with expert guides to make your trips unforgettable. " +
"Whether you are a seasoned traveler or just starting your journey, we are here to make it easier and more enjoyable!"
);
descriptionText.setFont(new Font("Arial", Font.PLAIN, 18));
descriptionText.setForeground(Color.WHITE);
descriptionText.setOpaque(false);
descriptionText.setEditable(false);
descriptionText.setLineWrap(true);
descriptionText.setWrapStyleWord(true);
descriptionText.setAlignmentX(Component.CENTER_ALIGNMENT);
descriptionText.setMaximumSize(new Dimension(600, 200));
// Create buttons
JButton registerGuideButton = new JButton("Register as Guide");
styleButton(registerGuideButton);
registerGuideButton.addActionListener(e -> mainFrame.showPage("GuideRegistrationPage"));
JButton registerTravelerButton = new JButton("Register as Traveler");
styleButton(registerTravelerButton);
registerTravelerButton.addActionListener(e -> mainFrame.showPage("TravelerRegistrationPage"));
JButton loginButton = new JButton("Login");
styleButton(loginButton);
loginButton.addActionListener(e -> mainFrame.showPage("LoginPage"));
// Add components to contentPanel
contentPanel.add(Box.createVerticalGlue());
contentPanel.add(headerLabel);
contentPanel.add(Box.createVerticalStrut(20));
contentPanel.add(descriptionText);
contentPanel.add(Box.createVerticalStrut(30));
contentPanel.add(registerGuideButton);
contentPanel.add(Box.createVerticalStrut(10));
contentPanel.add(registerTravelerButton);
contentPanel.add(Box.createVerticalStrut(10));
contentPanel.add(loginButton);
contentPanel.add(Box.createVerticalGlue());
// Add contentPanel to backgroundPanel
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
backgroundPanel.add(contentPanel, gbc);
// Add backgroundPanel to main panel
add(backgroundPanel, BorderLayout.CENTER);
}
private void styleButton(JButton button) {
button.setFont(new Font("Arial", Font.BOLD, 18));
button.setForeground(Color.BLACK);
button.setBackground(Color.WHITE);
button.setFocusPainted(false);
button.setBorderPainted(false);
button.setOpaque(true);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
button.setMaximumSize(new Dimension(400, 50));
button.setPreferredSize(new Dimension(400, 50));
// Add mouse hover effect
button.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
button.setBackground(new Color(64, 165, 120)); // A shade of green
button.setForeground(Color.WHITE);
}
public void mouseExited(MouseEvent e) {
button.setBackground(Color.WHITE);
button.setForeground(Color.BLACK);
}
});
}
// Custom JPanel to draw the background image
class BackgroundPanel extends JPanel {
private Image backgroundImage;
public BackgroundPanel(Image backgroundImage) {
this.backgroundImage = backgroundImage;
setPreferredSize(new Dimension(backgroundImage.getWidth(null), backgroundImage.getHeight(null)));
}
@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);
}
}
}