Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. package guifx;
  2.  
  3. import javafx.application.Application;
  4. import javafx.geometry.Insets;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.Label;
  8. import javafx.scene.control.ListView;
  9. import javafx.scene.control.TextField;
  10. import javafx.scene.layout.GridPane;
  11. import javafx.stage.Stage;
  12.  
  13. public class MainApp extends Application {
  14.  
  15. public static void main(String[] args) {
  16. Application.launch(args);
  17. }
  18.  
  19. @Override
  20. public void start(Stage stage) {
  21. stage.setTitle("AArhus Bryghus");
  22. GridPane pane = new GridPane();
  23. this.initContent(pane);
  24.  
  25. produktWindow = new ProduktInputWindow("Opret produkt", stage);
  26. Scene scene = new Scene(pane);
  27. stage.setScene(scene);
  28. stage.show();
  29.  
  30. }
  31.  
  32. // -------------------------------------------------------------------------
  33.  
  34. private TextField txfResult;
  35. private ListView<Produkt> lvwProdukt;
  36. private ProduktInputWindow produktWindow;
  37.  
  38.  
  39.  
  40. private void initContent(GridPane pane) {
  41. // show or hide grid lines
  42. pane.setGridLinesVisible(false);
  43.  
  44. // set padding of the pane
  45. pane.setPadding(new Insets(20));
  46. // set horizontal gap between components
  47. pane.setHgap(10);
  48. // set vertical gap between components
  49. pane.setVgap(10);
  50.  
  51. // add a label to the pane (at col=0, row=0)
  52. Label lblName = new Label("Produkt :");
  53. pane.add(lblName, 0, 0);
  54.  
  55. // add a text field to the pane
  56. // (at col=1, row=0, extending 2 columns and 1 row)
  57. txfResult = new TextField();
  58. pane.add(txfResult, 1, 0, 2, 1);
  59.  
  60. lvwProdukt = new ListView<Produkt>();
  61. pane.add(lvwProdukt, 1,1,3,1);
  62. lvwProdukt.setPrefWidth(200);
  63. lvwProdukt.setPrefHeight(200);
  64.  
  65. // add a button to the pane (at col=1, row=1)
  66. Button btnCreateMovie = new Button("Opret Produkt");
  67. pane.add(btnCreateMovie, 1, 1);
  68. GridPane.setMargin(btnCreateMovie, new Insets(10, 10, 0, 10));
  69.  
  70. // connect a method to the button
  71. btnCreateMovie.setOnAction(event -> this.createProduktAction());
  72.  
  73. }
  74.  
  75. // -----------------------------------------------------
  76. // Button actions
  77.  
  78. private void createProduktAction() {
  79. produktWindow.showAndWait();
  80. if (produktWindow.getActualProdukt() != null) {
  81. txfResult.setText(produktWindow.getActualProdukt().toString());
  82. }
  83.  
  84.  
  85.  
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement