- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrame.java
More file actions
Latest commit
145 lines (114 loc) · 5.91 KB
/
Copy pathMainFrame.java
File metadata and controls
145 lines (114 loc) · 5.91 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
140
141
142
143
144
145
importjavax.swing.*;
importjava.awt.*;
publicclassMainFrameextendsJFrame {
CardLayoutcardLayout = newCardLayout();
JPanelcontentPanel = newJPanel();
publicMainFrame() {
setTitle("Tour Guide App");
setSize(600, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
contentPanel.setLayout(cardLayout);
// Add different panels (pages)
contentPanel.add(newSelectionPage(this), "SelectionPage");
contentPanel.add(newGuideRegistrationPage(this), "GuideRegistrationPage");
contentPanel.add(newTravelerRegistrationPage(this), "TravelerRegistrationPage");
contentPanel.add(newLoginPage(this), "LoginPage");
add(contentPanel);
cardLayout.show(contentPanel, "SelectionPage"); // Show the initial page
}
// Method to switch between panels
publicvoidshowPage(Stringpage) {
cardLayout.show(contentPanel, page);
}
// Show guide profile page after successful login
// public void showGuideProfilePage(String[] userInfo) {
// GuideProfilePage guideProfilePage = new GuideProfilePage(this, userInfo);
// contentPanel.add(guideProfilePage, "GuideProfilePage");
// cardLayout.show(contentPanel, "GuideProfilePage");
// }
// Show traveler profile page after successful login
// public void showTravelerProfilePage(String[] userInfo) {
// TravelerProfilePage travelerProfilePage = new TravelerProfilePage(this, userInfo);
// contentPanel.add(travelerProfilePage, "TravelerProfilePage");
// cardLayout.show(contentPanel, "TravelerProfilePage");
// }
// Overloaded method: This version only takes username, and assumes isTraveler is null (optional)
/// Show SeeBookingTravelerPage using CardLayout
publicvoidshowSeeBookingTravelerPage(StringtravelerUsername) {
SeeBookingTravelerPageseeBookingTravelerPage = newSeeBookingTravelerPage(this, travelerUsername);
// Add the page to the contentPanel if it's not already added
contentPanel.add(seeBookingTravelerPage, "SeeBookingTravelerPage");
cardLayout.show(contentPanel, "SeeBookingTravelerPage");
}
// Ensure Back to Profile works via CardLayout
publicvoidshowProfilePage(Stringusername, BooleanisTraveler) {
System.err.println("---");
System.err.println(username);
// If isTraveler is explicitly true, load the Traveler profile
if (isTraveler != null && isTraveler) {
System.err.println("Traveler Profile");
String[] userInfo = getUserInfo(username, "TravelersData.txt");
showTravelerProfilePage(userInfo); // Show traveler profile
}
// If isTraveler is false or null, assume the user is a guide
else {
System.err.println("Guide Profile");
String[] userInfo = getUserInfo(username, "GuidesData.txt");
showGuideProfilePage(userInfo); // Show guide profile
}
}
// Example of showing the guide profile using CardLayout
publicvoidshowGuideProfilePage(String[] userInfo) {
GuideProfilePageguideProfilePage = newGuideProfilePage(this, userInfo);
// Add guide profile page to the content panel only if not added yet
contentPanel.add(guideProfilePage, "GuideProfilePage");
cardLayout.show(contentPanel, "GuideProfilePage");
}
// Example of showing the traveler profile using CardLayout
publicvoidshowTravelerProfilePage(String[] userInfo) {
TravelerProfilePagetravelerProfilePage = newTravelerProfilePage(this, userInfo);
// Add traveler profile page to the content panel only if not added yet
contentPanel.add(travelerProfilePage, "TravelerProfilePage");
cardLayout.show(contentPanel, "TravelerProfilePage");
}
// Show hire guide page
publicvoidshowHirePage(StringguideUsername,StringtravelerUsername) {
HireGuidePagehireGuidePage = newHireGuidePage(this, guideUsername,travelerUsername);
contentPanel.add(hireGuidePage, "HireGuidePage");
cardLayout.show(contentPanel, "HireGuidePage");
}
// Add this method to MainFrame
publicvoidshowAvailableGuidesPage(StringtravelerUsername) {
AvailableGuidesPageavailableGuidesPage = newAvailableGuidesPage(this,travelerUsername);
contentPanel.add(availableGuidesPage, "AvailableGuidesPage");
cardLayout.show(contentPanel, "AvailableGuidesPage");
}
publicvoidshowSeeBookingGuidePage(StringguideUsername) {
SeeBookingGuidePageseeBookingGuidePage = newSeeBookingGuidePage(this, guideUsername);
contentPanel.add(seeBookingGuidePage, "SeeBookingGuidePage");
cardLayout.show(contentPanel, "SeeBookingGuidePage");
}
// public void showSeeBookingTravelerPage(String travelerUsername) {
// SeeBookingTravelerPage seeBookingTravelerPage = new SeeBookingTravelerPage(this, travelerUsername);
// setContentPane(seeBookingTravelerPage);
// revalidate();
// }
// Show change password page for guide or traveler
publicvoidshowChangePasswordPage(Stringusername, StringfilePath,Stringuser) {
ChangePasswordPagechangePasswordPage = newChangePasswordPage(this, username, filePath,user);
contentPanel.add(changePasswordPage, "ChangePasswordPage");
cardLayout.show(contentPanel, "ChangePasswordPage");
}
// Helper method to get user info (You may replace with actual logic)
privateString[] getUserInfo(Stringusername, StringfilePath) {
// Fetch user information from the file based on username
returnnewString[] { "Name", "Phone", "Email", "Username", "Address" }; // Placeholder
}
publicstaticvoidmain(String[] args) {
SwingUtilities.invokeLater(() -> {
MainFramemainFrame = newMainFrame();
mainFrame.setVisible(true);
});
}
}