-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNewFXMain.java
215 lines (181 loc) · 8.54 KB
/
NewFXMain.java
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package project.trial;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Screen;
public class NewFXMain extends Application {
public static Scene loginscene;
@Override
public void start(Stage primaryStage) throws FileNotFoundException {
Users userSystem = new Users();
// Page format
BorderPane root = new BorderPane();
root.setStyle("-fx-background-color: #292525; -fx-background-image: url('file:/home/jana/Downloads/Project.jpg'); -fx-background-size: cover;");
// Image
Image i = new Image(new FileInputStream("/home/jana/Downloads/user(1).png"));
ImageView iv = new ImageView(i);
iv.setFitHeight(150);
iv.setFitWidth(150);
// Functionality...
// Labels
Label ID = new Label("ID:");
ID.setTextFill(Color.web("#ffb000"));
ID.setFont(Font.font("Helvetica World", FontWeight.BOLD, 30));
Label passw = new Label("Password:");
passw.setTextFill(Color.web("#ffb000"));
passw.setFont(Font.font("Helvetica World", FontWeight.BOLD, 30));
// Fields
TextField id = new TextField();
id.setMinSize(300, 60); // Adjust the size as needed
id.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-border-width: 4px; -fx-text-fill: #ffb000; -fx-font-size: 18px;");
PasswordField password = new PasswordField();
password.setMinSize(300, 60); // Adjust the size as needed
password.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-border-width: 4px; -fx-text-fill: #ffb000; -fx-font-size: 18px;");
// Buttons
Button login = new Button("Login");
login.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
login.setPrefWidth(300);
login.setFont(Font.font("Helvetica World", FontWeight.BOLD, 24));
login.setOnMouseEntered(eh ->
{
login.setCursor(Cursor.HAND);
login.setStyle("-fx-background-color: transparent; -fx-border-color: white; -fx-border-radius: 5px; -fx-text-fill: white; -fx-border-width: 4px;");
});
// non-hover event
login.setOnMouseExited(eh ->
{
login.setCursor(Cursor.DEFAULT);
login.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
});
// GridPane
GridPane gridpane = new GridPane();
gridpane.add(ID, 0, 0);
gridpane.add(id, 1, 0);
gridpane.add(passw, 0, 1);
gridpane.add(password, 1, 1);
gridpane.setAlignment(Pos.CENTER);
gridpane.setHgap(40);
gridpane.setVgap(25);
// VBox
VBox vbox = new VBox();
vbox.setMinSize(600, 600);
vbox.getChildren().addAll(iv, gridpane, login);
vbox.setSpacing(50);
vbox.setAlignment(Pos.CENTER);
// StackPane
StackPane stackpane = new StackPane();
Rectangle rectangle = new Rectangle(600, 600);
rectangle.setArcWidth(20);
rectangle.setArcHeight(20);
rectangle.setFill(Color.rgb(10,12,38, 0.5));
rectangle.setStyle("-fx-border-radius: 5px;");
stackpane.getChildren().addAll(rectangle, vbox);
// Adding items to the page
root.setCenter(stackpane);
Region centerRegion = (Region) root.getCenter();
centerRegion.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
// Event handler for buttons
login.setOnAction(e ->
{
try {
int ident = Integer.parseInt(id.getText());
int userType;
try {
userType = userSystem.Login2(ident, password.getText());
if (userType != -1) {
switch (userType) {
case 0:
//admin home page
for(Admin a: Admin.admins)
{
if(a.ID == ident)
{
Scene AdminsScene = a.HomePageScene();
primaryStage.setScene(AdminsScene);
primaryStage.setTitle("Bus-Ticket Booking System - Admin HomePage");
}
}
break;
case 1:
//receptionist home page
for(Receptionist r: Receptionist.receptionists)
{
if(r.ID == ident)
{
primaryStage.setScene(r.ManageBookings(primaryStage));
primaryStage.setTitle("Bus-Ticket Booking System - Receptionist HomePage");
}
}
break;
case 2:
//guest home page
for(Guest g: Guest.guests.values())
{
if(g.ID == ident)
{
primaryStage.setScene(g.guestHomePage());
primaryStage.setTitle("Bus-Ticket Booking System - Guest HomePage");
}
}
break;
default:
break;
}
} else {
showAlert(AlertType.WARNING, "Login Failed", "Invalid ID or Password. Please try again.");
}
} catch (FileNotFoundException ex) {
System.out.println(ex);
}
} catch (NumberFormatException x) {
showAlert(AlertType.WARNING, "Invalid ID format", "Please enter a valid Integer ID.");
}
id.clear();
password.clear();
});
loginscene = new Scene(root, Screen.getPrimary().getVisualBounds().getWidth(), Screen.getPrimary().getVisualBounds().getHeight());
primaryStage.setTitle("Bus-Ticket Booking System - Login Page");
primaryStage.setScene(loginscene);
primaryStage.setFullScreen(true);
primaryStage.show();
}
private void showAlert(AlertType alertType, String title, String content) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(content);
alert.showAndWait();
}
//Admin@Parent101
public static void main(String[] args) throws IOException {
Admin.readUsersFromFile();
Guest.loadGuestsFromBinaryFile();
Vehicle.readFromFile();
Booking.readFromFile();
Trips t = new Trips();
t.DisplayTrips();
Vehicle.initializeAvailibilityMap();
Admin ParentAdmin = new Admin(101, "101", "Parent_Admin");
Receptionist recep = new Receptionist(102, "101", "Receptionist_1");
Guest guest = new Guest(103, "101", "Guest_1");
launch(args);
Vehicle.updateFile();
Booking.saveToFile();
Guest.saveGuestsToBinaryFile();
Admin.saveUsersToFile();
}
}