- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionPage.java
More file actions
Latest commit
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
importjavax.swing.*;
importjavax.swing.text.JTextComponent;
importjava.awt.*;
importjava.awt.event.MouseAdapter;
importjava.awt.event.MouseEvent;
publicclassSelectionPageextendsJPanel {
publicSelectionPage(MainFramemainFrame) {
setLayout(newBorderLayout());
// Set the background image
ImageIconbackgroundImageIcon = newImageIcon("travel.jpg"); // Replace with your image file
ImagebackgroundImage = backgroundImageIcon.getImage();
BackgroundPanelbackgroundPanel = newBackgroundPanel(backgroundImage);
backgroundPanel.setLayout(newGridBagLayout()); // To center the contentPanel
// Create a panel to hold the text and buttons
JPanelcontentPanel = newJPanel();
contentPanel.setLayout(newBoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.setOpaque(false); // Make it transparent to show background image
// Add some text (header and description)
JLabelheaderLabel = newJLabel("Welcome to our Travel App!");
headerLabel.setFont(newFont("Arial", Font.BOLD, 28));
headerLabel.setForeground(Color.WHITE);
headerLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
JTextAreadescriptionText = newJTextArea(
"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(newFont("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(newDimension(600, 200));
// Create buttons
JButtonregisterGuideButton = newJButton("Register as Guide");
styleButton(registerGuideButton);
registerGuideButton.addActionListener(e -> mainFrame.showPage("GuideRegistrationPage"));
JButtonregisterTravelerButton = newJButton("Register as Traveler");
styleButton(registerTravelerButton);
registerTravelerButton.addActionListener(e -> mainFrame.showPage("TravelerRegistrationPage"));
JButtonloginButton = newJButton("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
GridBagConstraintsgbc = newGridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
backgroundPanel.add(contentPanel, gbc);
// Add backgroundPanel to main panel
add(backgroundPanel, BorderLayout.CENTER);
}
privatevoidstyleButton(JButtonbutton) {
button.setFont(newFont("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(newCursor(Cursor.HAND_CURSOR));
button.setMaximumSize(newDimension(400, 50));
button.setPreferredSize(newDimension(400, 50));
// Add mouse hover effect
button.addMouseListener(newMouseAdapter() {
publicvoidmouseEntered(MouseEvente) {
button.setBackground(newColor(64, 165, 120)); // A shade of green
button.setForeground(Color.WHITE);
}
publicvoidmouseExited(MouseEvente) {
button.setBackground(Color.WHITE);
button.setForeground(Color.BLACK);
}
});
}
// Custom JPanel to draw the background image
classBackgroundPanelextendsJPanel {
privateImagebackgroundImage;
publicBackgroundPanel(ImagebackgroundImage) {
this.backgroundImage = backgroundImage;
setPreferredSize(newDimension(backgroundImage.getWidth(null), backgroundImage.getHeight(null)));
}
@Override
protectedvoidpaintComponent(Graphicsg) {
super.paintComponent(g);
// Draw the background image scaled to fit the panel
g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
}
}
}