Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import application.model.Hotel;
- import controller.Controller;
- import javafx.geometry.HPos;
- import javafx.geometry.Insets;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.stage.Stage;
- public class PopupCreateHotel extends Stage {
- private TextField txfName, txfPriceSingle, txfPriceDouble;
- private Label lblName, lblPriceSingle, lblPriceDouble, lblError;
- private Button btnOK, btnCancel;
- private Hotel hotel;
- public PopupCreateHotel() {
- setTitle("Create Hotel");
- GridPane pane = new GridPane();
- initContent(pane);
- Scene scene = new Scene(pane);
- setScene(scene);
- }
- private void initContent(GridPane pane) {
- pane.setPadding(new Insets(10));
- pane.setHgap(10);
- pane.setVgap(10);
- pane.setGridLinesVisible(true);
- lblName = new Label("Name");
- pane.add(lblName, 0, 0);
- txfName = new TextField();
- pane.add(txfName, 1, 0);
- lblPriceSingle = new Label("Single Room Price");
- pane.add(lblPriceSingle, 0, 1);
- txfPriceSingle = new TextField();
- pane.add(txfPriceSingle, 1, 1);
- lblPriceDouble = new Label("Double Room Price");
- pane.add(lblPriceDouble, 0, 2);
- txfPriceDouble = new TextField();
- pane.add(txfPriceDouble, 1, 2);
- btnCancel = new Button("Cancel");
- pane.add(btnCancel, 0, 3);
- GridPane.setHalignment(btnCancel, HPos.LEFT);
- btnCancel.setOnAction(event -> this.cancelAction());
- btnOK = new Button("OK");
- pane.add(btnOK, 1, 3);
- GridPane.setHalignment(btnOK, HPos.RIGHT);
- btnOK.setOnAction(event -> this.okAction());
- lblError = new Label();
- pane.add(lblError, 0, 4);
- lblError.setStyle("-fx-text-fill: red");
- }
- private void okAction() {
- String name = txfName.getText().trim();
- if (name == null) {
- lblError.setText("Name is empty");
- return;
- }
- int priceSingle = Integer.parseInt(txfPriceSingle.getText().trim());
- if (priceSingle == 0) {
- lblError.setText("Please enter the price for a single room");
- return;
- }
- int priceDouble = Integer.parseInt(txfPriceDouble.getText().trim());
- if (priceDouble == 0) {
- lblError.setText("Please enter the price for a double room");
- return;
- }
- hotel = Controller.createHotel(name, priceSingle, priceDouble);
- this.hide();
- }
- private void cancelAction() {
- this.hide();
- }
- public Hotel getHotel() {
- return this.hotel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement