Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. package guifx;
  2.  
  3. import javafx.geometry.Insets;
  4. import javafx.geometry.Pos;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Alert;
  7. import javafx.scene.control.Alert.AlertType;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.TextField;
  11. import javafx.scene.layout.GridPane;
  12. import javafx.scene.layout.HBox;
  13. import javafx.stage.Modality;
  14. import javafx.stage.Stage;
  15. import javafx.stage.StageStyle;
  16.  
  17. public class ProduktInputWindow extends Stage {
  18. public ProduktInputWindow(String title, Stage owner) {
  19. this.initOwner(owner);
  20. this.initStyle(StageStyle.UTILITY);
  21. this.initModality(Modality.APPLICATION_MODAL);
  22. this.setMinHeight(100);
  23. this.setMinWidth(200);
  24. this.setResizable(false);
  25.  
  26. this.setTitle(title);
  27. GridPane pane = new GridPane();
  28. this.initContent(pane);
  29.  
  30. Scene scene = new Scene(pane);
  31. this.setScene(scene);
  32. }
  33.  
  34. // -------------------------------------------------------------------------
  35. private TextField txfNavn;
  36. private TextField txfMængde;
  37.  
  38. private Produkt actualProdukt = null;
  39.  
  40. private void initContent(GridPane pane) {
  41. // pane.setGridLinesVisible(true);
  42. pane.setPadding(new Insets(20));
  43. pane.setHgap(10);
  44. pane.setVgap(10);
  45.  
  46. Label lblNavn = new Label("Navn :");
  47. pane.add(lblNavn, 0, 0);
  48.  
  49.  
  50. Label lblMængde = new Label("Mængde :");
  51. pane.add(lblMængde, 0, 2);
  52.  
  53. txfNavn = new TextField();
  54. pane.add(txfNavn, 1, 0, 2, 1);
  55.  
  56.  
  57. txfMængde = new TextField();
  58. pane.add(txfMængde, 1, 1, 2, 1);
  59.  
  60. HBox buttonBox = new HBox(20);
  61. pane.add(buttonBox, 0, 3);
  62. buttonBox.setPadding(new Insets(10, 10, 0, 10));
  63. buttonBox.setAlignment(Pos.TOP_RIGHT);
  64.  
  65. Button btnCancel = new Button("Cancel");
  66. buttonBox.getChildren().add(btnCancel);
  67. btnCancel.setOnAction(event -> this.cancelAction());
  68.  
  69. Button btnOK = new Button("OK");
  70. buttonBox.getChildren().add(btnOK);
  71. btnOK.setOnAction(event -> this.okAction());
  72. }
  73.  
  74. // -------------------------------------------------------------------------
  75.  
  76. // -------------------------------------------------------------------------
  77. // Button actions
  78.  
  79. private void cancelAction() {
  80. txfNavn.clear();
  81. txfNavn.requestFocus();
  82. txfMængde.clear();
  83. actualProdukt = null;
  84. ProduktInputWindow.this.hide();
  85. }
  86.  
  87. private void okAction() {
  88. String navn = txfNavn.getText().trim();
  89. String mængde = txfMængde.getText().trim();
  90.  
  91.  
  92. if (navn.length() > 0 && mængde.length() > 0) {
  93. actualProdukt = new Produkt(navn, mængde);
  94. txfNavn.clear();
  95. txfMængde.clear();
  96.  
  97. txfNavn.requestFocus();
  98. ProduktInputWindow.this.hide();
  99. } else {
  100. Alert alert = new Alert(AlertType.INFORMATION);
  101. alert.setTitle("Create Produkt");
  102. alert.setHeaderText("Information missing");
  103. alert.setContentText("Indtast navn og Mængde");
  104. alert.show();
  105. }
  106.  
  107. }
  108.  
  109. public Produkt getActualProdukt() {
  110. return actualProdukt;
  111. }
  112.  
  113. public void clearActualMovie() {
  114. actualProdukt = null;
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement