Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. package gui;
  2.  
  3. import javafx.scene.control.TextField;
  4. import javafx.scene.layout.GridPane;
  5. import application.model.Hotel;
  6. import controller.Controller;
  7. import javafx.geometry.HPos;
  8. import javafx.geometry.Insets;
  9. import javafx.scene.Scene;
  10. import javafx.scene.control.Button;
  11. import javafx.scene.control.Label;
  12.  
  13. import javafx.stage.Stage;
  14.  
  15. public class PopupCreateHotel extends Stage {
  16. private TextField txfName, txfPriceSingle, txfPriceDouble;
  17. private Label lblName, lblPriceSingle, lblPriceDouble, lblError;
  18. private Button btnOK, btnCancel;
  19. private Hotel hotel;
  20.  
  21. public PopupCreateHotel() {
  22. setTitle("Create Hotel");
  23. GridPane pane = new GridPane();
  24. initContent(pane);
  25.  
  26. Scene scene = new Scene(pane);
  27. setScene(scene);
  28. }
  29.  
  30. private void initContent(GridPane pane) {
  31. pane.setPadding(new Insets(10));
  32. pane.setHgap(10);
  33. pane.setVgap(10);
  34. pane.setGridLinesVisible(true);
  35.  
  36. lblName = new Label("Name");
  37. pane.add(lblName, 0, 0);
  38. txfName = new TextField();
  39. pane.add(txfName, 1, 0);
  40.  
  41. lblPriceSingle = new Label("Single Room Price");
  42. pane.add(lblPriceSingle, 0, 1);
  43. txfPriceSingle = new TextField();
  44. pane.add(txfPriceSingle, 1, 1);
  45.  
  46. lblPriceDouble = new Label("Double Room Price");
  47. pane.add(lblPriceDouble, 0, 2);
  48. txfPriceDouble = new TextField();
  49. pane.add(txfPriceDouble, 1, 2);
  50.  
  51. btnCancel = new Button("Cancel");
  52. pane.add(btnCancel, 0, 3);
  53. GridPane.setHalignment(btnCancel, HPos.LEFT);
  54. btnCancel.setOnAction(event -> this.cancelAction());
  55.  
  56. btnOK = new Button("OK");
  57. pane.add(btnOK, 1, 3);
  58. GridPane.setHalignment(btnOK, HPos.RIGHT);
  59. btnOK.setOnAction(event -> this.okAction());
  60.  
  61. lblError = new Label();
  62. pane.add(lblError, 0, 4);
  63. lblError.setStyle("-fx-text-fill: red");
  64. }
  65.  
  66. private void okAction() {
  67. String name = txfName.getText().trim();
  68. if (name == null) {
  69. lblError.setText("Name is empty");
  70. return;
  71. }
  72. int priceSingle = Integer.parseInt(txfPriceSingle.getText().trim());
  73. if (priceSingle == 0) {
  74. lblError.setText("Please enter the price for a single room");
  75. return;
  76. }
  77. int priceDouble = Integer.parseInt(txfPriceDouble.getText().trim());
  78. if (priceDouble == 0) {
  79. lblError.setText("Please enter the price for a double room");
  80. return;
  81. }
  82.  
  83. hotel = Controller.createHotel(name, priceSingle, priceDouble);
  84. this.hide();
  85. }
  86.  
  87. private void cancelAction() {
  88. this.hide();
  89. }
  90.  
  91. public Hotel getHotel() {
  92. return this.hotel;
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement