Advertisement
sergAccount

Untitled

Sep 27th, 2020
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package com.mycompany.mavenproject2;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.ActionEvent;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.Label;
  8. import javafx.scene.layout.StackPane;
  9. import javafx.stage.Stage;
  10.  
  11. public class App extends Application {
  12.  
  13.     @Override
  14.     public void start(Stage stage) {
  15.         var javaVersion = SystemInfo.javaVersion();
  16.         var javafxVersion = SystemInfo.javafxVersion();
  17.         //
  18.         var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
  19.         // создание панели
  20.         StackPane sPane = new StackPane();
  21.         // добавляем элемент управления
  22.         sPane.getChildren().add(label);
  23.         // создаем объект - кнопка
  24.         Button btn = new Button("OK");
  25.         // для установки обработчик - используем метод setOnAction
  26.         // лямбда - выражение
  27.         //btn.setOnAction(e -> {System.out.println("OK BUTTON!!!");});
  28.         //
  29.         btn.setOnAction(this::onOkButton);
  30.         //
  31.         sPane.getChildren().add(btn);
  32.        
  33.         var scene = new Scene(sPane, 640, 480);
  34.         stage.setScene(scene);
  35.         stage.show();
  36.     }
  37.     //
  38.     private void onOkButton(ActionEvent ae){
  39.         //
  40.         System.out.println("ae=" + ae);
  41.         System.out.println("OK BUTTON!!!");
  42.     }
  43.  
  44.     public static void main(String[] args) {
  45.         launch();
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement