Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.87 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package fxdemo1;
  7.  
  8. import javafx.geometry.Insets;
  9. import javafx.application.Application;
  10. import javafx.application.Platform;
  11. import javafx.event.ActionEvent;
  12. import javafx.scene.Scene;
  13. import javafx.scene.control.Button;
  14. import javafx.scene.control.Label;
  15. import javafx.scene.control.TextField;
  16. import javafx.scene.layout.FlowPane;
  17. import javafx.scene.layout.VBox;
  18. import javafx.scene.text.Font;
  19. import javafx.scene.text.FontPosture;
  20. import javafx.scene.text.FontWeight;
  21. import javafx.scene.text.Text;
  22. import javafx.stage.Stage;
  23.  
  24. public class FXDemo1 extends Application {
  25.     //
  26.     public static void main(String[] args) {
  27.         // TODO code application logic here
  28.         launch(args);
  29.     }    
  30.     @Override
  31.     public void start(Stage stage) throws Exception {
  32.         System.out.println("FXDemo1.start>>");
  33.         String javaVersion   = System.getProperty("java.version");
  34.         String javafxVersion = System.getProperty("javafx.version");
  35.         //
  36.         System.out.println("javaVersion=" + javaVersion);       // JAVA  11 >
  37.         System.out.println("javafxVersion=" + javafxVersion);   // JAVAFX14 >
  38.         // создаем корневой узел - используем панель поточной компоновки
  39.         FlowPane pane = new FlowPane();        
  40.         // создаем элементы управления
  41.         Button btn1 = new Button("Ok");
  42.         btn1.setText("Ok1");
  43.        
  44.         TextField textField = new TextField();
  45.         // указываем обработчик события дял кнопки btn1 (используем lambda-выражения)
  46.         btn1.setOnAction((ActionEvent event) -> {
  47.             System.out.println("Press OK BUTTON");
  48.             // получаем источник события
  49.             Object source = event.getSource();
  50.             System.out.println("source=" + source);
  51.             textField.setText("Новый текст!!!");
  52.            
  53.             //textField.getText()
  54.         });                
  55.         // в панель добавляем кнопку          
  56.         pane.getChildren().add(btn1);
  57.         //
  58.         Button btn2 = new Button("Exit");
  59.         // указываем обработчик события дял кнопки btn2 (используем ссылку на метод)
  60.         btn2.setOnAction(this::onExitEvent);
  61.                
  62.         pane.getChildren().add(btn2);        
  63.         // Label
  64.         Label l1 = new Label("Text:");
  65.         pane.getChildren().add(l1);    
  66.         // Text
  67.         Text text = new Text();  
  68.         text.setText("Hello how are you");
  69.         text.setFont(Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 20));
  70.         pane.getChildren().add(text);    
  71.         //
  72.         //TextField textField = new TextField();
  73.         textField.setMinWidth(120);
  74.         pane.getChildren().add(textField);            
  75.         // создаем сцену (объект типа Scene)
  76.         Scene scene = new Scene(pane, 800, 600);                  
  77.         // заголовок окна (подмостка)
  78.         stage.setTitle("JavaFX FXDemo1");
  79.         //        
  80.         /*
  81.         VBox vbox = new VBox();
  82.         // установка вертикального расстояния между элементами в контейнере
  83.         vbox.setSpacing(10);
  84.         // установка отступов с помощью объекта типа Insets:
  85.         vbox.setPadding(new Insets(15, 20, 10, 10));
  86.         */
  87.         stage.setScene(scene);
  88.         // показ окна на экране
  89.         stage.show();
  90.     }
  91.     //    
  92.     private void onExitEvent(ActionEvent t) {        
  93.         System.out.println("onExitEvent call>>");
  94.         // Platform.exit - для заверщения FX приложения  
  95.         Platform.exit();
  96.         //System.exit(0);
  97.     }
  98.     //
  99.     // переопределить метод init()
  100.     @Override
  101.     public void init(){
  102.         System.out.println("FXDemo1.init>>");
  103.     }    
  104.     // переопределить метод stop()    
  105.     @Override
  106.     public void stop(){
  107.         System.out.println("FXDemo1.stop>>");
  108.     }  
  109. }
  110.  
  111.  
  112. /*
  113. Starts the JavaFX runtime, if not already started (see Platform.startup(Runnable) for more information)
  114. Constructs an instance of the specified Application class
  115. Calls the init() method
  116. Calls the start(javafx.stage.Stage) method
  117. Waits for the application to finish, which happens when either of the following occur:
  118. the application calls Platform.exit()
  119. the last window has been closed and the implicitExit attribute on Platform is true
  120. Calls the stop() method
  121. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement