0% found this document useful (0 votes)
7 views

Message

Uploaded by

blendkika038
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Message

Uploaded by

blendkika038
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

public class UImainn extends Application {

Scanner scan = new Scanner(System.in);


private Scene welcome;
private Scene carSelectionScene;
private Scene staffScene;

@Override
public void start(Stage stage) throws Exception {
Label nameLabel = new Label("FullName:");
TextField textField = new TextField();
Label emailLabel = new Label("Email:");
TextField tfEmail = new TextField();
Label phoneLabel = new Label("Driving License ID:");
TextField tfPhone = new TextField();

Button btn = new Button();


btn.setText("Login");
btn.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white;");

btn.setOnAction(event -> switchScreen(stage));

VBox hBox = new VBox();


hBox.setSpacing(10);
hBox.getChildren().setAll(
nameLabel, textField,
emailLabel, tfEmail,
phoneLabel, tfPhone,
btn
);
hBox.setStyle("-fx-background-color: lightBlue; -fx-border-color: white; -
fx-alignment: center;");
welcome = new Scene(hBox, 300, 250);
stage.setScene(welcome);
stage.show();
}

private void switchScreen(Stage stage) {


Label label = new Label();
label.setText("Zgjedhni Veturen");

ListView<Car> carsListView = new ListView<>();


carsListView.getItems().addAll(
new Car("BMW", RentalStatus.Available, Transmission.Automatic,
FormCategory.Luxury, 1000, "12/04/2019",
getClass().getResource("/player12/BMW.jpeg").toString(),"Luxury BMW car with
automatic transmission. \n 150$ A day to rent ",150),
new Car("Mercedes", RentalStatus.Rented, Transmission.Automatic,
FormCategory.Luxury, 2399, "18/06/2017",
getClass().getResource("/player12/mercedes.jpeg").toString(), "Luxurious Mercedes,
currently rented.\n 130$ A day to rent",130),
new Car("Tesla", RentalStatus.Available, Transmission.Automatic,
FormCategory.Hybrid, 3899, "23/02/2022",
getClass().getResource("/player12/Tesla.jpeg").toString(), "Eco-friendly Tesla with
hybrid engine.\n 250$ A day to rent",250),
new Car("Toyota", RentalStatus.Available, Transmission.Manual,
FormCategory.Sport, 14564, "29/07/2016",
getClass().getResource("/player12/Toyota.jpeg").toString(),"Sporty Toyota with
manual transmission.\n 55$ A day to rent",55),
new Car("Audi", RentalStatus.UnderMaintenance,
Transmission.Automatic, FormCategory.Convertible, 4532, "15/04/2018",
getClass().getResource("/player12/Audi.jpg").toString(),"Convertible Audi, under
maintenance.\n 130$ A day to rent ",130),
new Car("Honda", RentalStatus.Available, Transmission.Manual,
FormCategory.Convertible, 6231, "06/09/2013",
getClass().getResource("/player12/Hondaaa.jpeg").toString(),"Convertible Honda with
manual transmission.\n 50$ A day to rent",50),
new Car("Ford", RentalStatus.Rented, Transmission.Manual,
FormCategory.Sedan, 4212, "14/08/2015",
getClass().getResource("/player12/Ford.jpg").toString(),"Sedan Ford, currently
rented.\n 35$ A day to rent",35)
);

carsListView.setCellFactory(param -> new ListCell<Car>() {


private final ImageView imageView = new ImageView();
private final Button detailsButton = new Button("View Details");
private final VBox vbox = new VBox();

{
detailsButton.setOnAction(event -> {
Car car = getItem();
if (car != null) {
showCarDetails(stage, car);
}
});
}

@Override
protected void updateItem(Car car, boolean empty) {
super.updateItem(car, empty);

if (empty || car == null) {


setText(null);
setGraphic(null);
} else {
imageView.setImage(new Image(car.getImagePath()));
imageView.setFitHeight(100);
imageView.setFitWidth(150);
setText(car.getBrand() + " - " + car.getRentalStatus());
vbox.getChildren().setAll(imageView, new Label(car.getBrand() +
" - " + car.getRentalStatus()), detailsButton);
setGraphic(vbox);
}
}
});

Button backButton = new Button("Back");


backButton.setOnAction(event -> stage.setScene(welcome));

Button staffButton = new Button("View Staff");


staffButton.setOnAction(event -> showStaff(stage));

VBox carSelectionVBox = new VBox(10);


carSelectionVBox.getChildren().addAll(label, carsListView, staffButton,
backButton);

carSelectionScene = new Scene(carSelectionVBox, 500, 500);


stage.setScene(carSelectionScene);
}
private void showCarDetails(Stage stage, Car car) {
Label carDetailsLabel = new Label(car.getDetails());
ImageView carImageView = new ImageView(new Image(car.getImagePath()));
carImageView.setFitHeight(250);
carImageView.setFitWidth(400);

Label daysLabel = new Label("Number of days:");


TextField daysField = new TextField();

Button rentButton = new Button("Rent");


rentButton.setOnAction(event -> {
int days;
try {
days = Integer.parseInt(daysField.getText());
car.rentCar(days);
carDetailsLabel.setText(car.getDetails()); // Update details to
reflect rental status
} catch (NumberFormatException e) {
System.out.println("Please enter a valid number of days.");
}
});

Button backButton = new Button("Back");


backButton.setOnAction(event -> stage.setScene(carSelectionScene));

VBox carDetailsVBox = new VBox(10);


carDetailsVBox.getChildren().addAll(carImageView,
carDetailsLabel,daysLabel, daysField,rentButton, backButton);

Scene carDetailsScene = new Scene(carDetailsVBox, 400, 400);


stage.setScene(carDetailsScene);
}
private void showStaff(Stage stage) {
ListView<Staff> staffListView = new ListView<>();
staffListView.getItems().addAll(
new Staff("Vali Corleone", 141411, 15),
new Staff("Dada Gashi", 441121, 15),
new Staff("Gramos Krasniqi", 653743, 15),
new Staff("Feronit Shabani", 181615, 15),
new Staff("Valmir Peci", 391417, 15)
);

staffListView.setCellFactory(param -> new ListCell<Staff>() {


@Override
protected void updateItem(Staff staff, boolean empty) {
super.updateItem(staff, empty);
if (empty || staff == null) {
setText(null);
} else {
setText(staff.getName() + " - ID: " + staff.getId() + " -
Experience: " + staff.getExperience() + " years");
}
}
});

Button backButton = new Button("Back");


backButton.setOnAction(event -> stage.setScene(carSelectionScene));

VBox staffVBox = new VBox(10);


staffVBox.getChildren().addAll(new Label("Staff List"), staffListView,
backButton);

staffScene = new Scene(staffVBox, 400, 400);


stage.setScene(staffScene);
}

public static void main(String[] args) {


launch();
}
}

You might also like