Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. package guifx;
  2.  
  3. import application.controller.Controller;
  4. import application.model.Companion;
  5. import application.model.Registration;
  6. import javafx.geometry.HPos;
  7. import javafx.geometry.Insets;
  8. import javafx.geometry.Pos;
  9. import javafx.scene.Scene;
  10. import javafx.scene.control.Button;
  11. import javafx.scene.control.Label;
  12. import javafx.scene.control.ListView;
  13. import javafx.scene.control.TextField;
  14. import javafx.scene.layout.GridPane;
  15. import javafx.scene.layout.HBox;
  16. import javafx.stage.Modality;
  17. import javafx.stage.Stage;
  18. import javafx.stage.StageStyle;
  19.  
  20. public class CreateCompanionWindow extends Stage {
  21. private Registration registration;
  22.  
  23.  
  24. public CreateCompanionWindow(String title, Registration registration) {
  25. initStyle(StageStyle.UTILITY);
  26. initModality(Modality.APPLICATION_MODAL);
  27. setResizable(false);
  28. System.out.println( "tjek reg11"+registration);
  29.  
  30. this.registration = registration;
  31.  
  32. setTitle(title);
  33. GridPane pane = new GridPane();
  34. initContent(pane);
  35.  
  36. Scene scene = new Scene(pane);
  37. setScene(scene);
  38. }
  39.  
  40. public CreateCompanionWindow(String title) {
  41. this(title, null);
  42. }
  43.  
  44. //-----------------------------------------------------------------------------------------------------
  45.  
  46. private TextField txfName, txfAddress, txfCountry, txfPhoneNumber, txfCity;
  47. private ListView<Companion> lvwCompanions;
  48. private Label lblError;
  49.  
  50. private void initContent(GridPane pane) {
  51. pane.setPadding(new Insets(10));
  52. pane.setHgap(10);
  53. pane.setVgap(10);
  54. pane.setGridLinesVisible(false);
  55.  
  56. // Labels oprettes
  57. Label lblName = new Label("Name:");
  58. pane.add(lblName, 0, 0);
  59.  
  60. Label lblAddress = new Label("Address:");
  61. pane.add(lblAddress, 0, 2);
  62.  
  63. Label lblCity = new Label("City:");
  64. pane.add(lblCity, 0, 4);
  65.  
  66. Label lblPhoneNumber = new Label("Phone number:");
  67. pane.add(lblPhoneNumber, 1, 0);
  68.  
  69. Label lblCountry = new Label("Country:");
  70. pane.add(lblCountry, 1, 2);
  71.  
  72. lblError = new Label();
  73. pane.add(lblError, 0, 5);
  74. lblError.setStyle("-fx-text-fill: red");
  75.  
  76. // Tekstfelter oprettes
  77. txfName = new TextField();
  78. pane.add(txfName, 0, 1);
  79.  
  80. txfAddress = new TextField();
  81. pane.add(txfAddress, 0, 3);
  82.  
  83. txfCountry = new TextField();
  84. pane.add(txfCountry, 1, 3);
  85.  
  86. txfPhoneNumber = new TextField();
  87. pane.add(txfPhoneNumber, 1, 1);
  88.  
  89. txfCity = new TextField();
  90. pane.add(txfCity, 0, 5);
  91.  
  92. // Kanpper oprettes
  93. HBox hbxButtons = new HBox(40);
  94. pane.add(hbxButtons, 0, 6, 3, 1);
  95. hbxButtons.setPadding(new Insets(10, 0, 0, 0));
  96. hbxButtons.setAlignment(Pos.BASELINE_RIGHT);
  97.  
  98. Button btnCancel = new Button("Cancel");
  99. hbxButtons.getChildren().add(btnCancel);
  100. GridPane.setHalignment(btnCancel, HPos.LEFT);
  101. btnCancel.setOnAction(event -> this.cancelAction());
  102.  
  103. Button btnOk = new Button("Ok");
  104. hbxButtons.getChildren().add(btnOk);
  105. GridPane.setHalignment(btnOk, HPos.LEFT);
  106. btnOk.setOnAction(event -> this.okAction());
  107. }
  108.  
  109. // private void initControls() {
  110. // if (registartion != null) {
  111. // txfName.setText(registartion.getName());
  112. // } else {
  113. // txfName.clear();
  114. // }
  115. // }
  116.  
  117. //--------------------------------------------------------------------------------------------------------
  118. private void cancelAction() {
  119. this.hide();
  120. }
  121.  
  122. private void okAction() {
  123. String name = txfName.getText().trim();
  124. String address = txfAddress.getText().trim();
  125. String country = txfCountry.getText().trim();
  126. String city = txfCity.getText().trim();
  127. String phoneNumber = txfPhoneNumber.getText().trim();
  128.  
  129. if(name == null && address == null && country == null && city == null && phoneNumber == null) {
  130. showReceiptAction();
  131. }else {
  132.  
  133. Controller.createCompanion(registration, name, address, country, city, phoneNumber);
  134. showReceiptAction();
  135. }
  136. hide();
  137. }
  138.  
  139. private void showReceiptAction() {
  140. ReceiptWindow dia = new ReceiptWindow("Receipt", registration);
  141. dia.showAndWait();
  142.  
  143.  
  144.  
  145.  
  146. }
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement