Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mycompany.mavenproject2;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- public class App extends Application {
- @Override
- public void start(Stage stage) {
- var javaVersion = SystemInfo.javaVersion();
- var javafxVersion = SystemInfo.javafxVersion();
- //
- var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
- // создание панели
- StackPane sPane = new StackPane();
- // добавляем элемент управления
- sPane.getChildren().add(label);
- // создаем объект - кнопка
- Button btn = new Button("OK");
- // для установки обработчик - используем метод setOnAction
- // лямбда - выражение
- //btn.setOnAction(e -> {System.out.println("OK BUTTON!!!");});
- //
- btn.setOnAction(this::onOkButton);
- //
- sPane.getChildren().add(btn);
- var scene = new Scene(sPane, 640, 480);
- stage.setScene(scene);
- stage.show();
- }
- //
- private void onOkButton(ActionEvent ae){
- //
- System.out.println("ae=" + ae);
- System.out.println("OK BUTTON!!!");
- }
- public static void main(String[] args) {
- launch();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement