Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package fxdemo1;
- import javafx.geometry.Insets;
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.event.ActionEvent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.FlowPane;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.scene.text.FontPosture;
- import javafx.scene.text.FontWeight;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- public class FXDemo1 extends Application {
- //
- public static void main(String[] args) {
- // TODO code application logic here
- launch(args);
- }
- @Override
- public void start(Stage stage) throws Exception {
- System.out.println("FXDemo1.start>>");
- String javaVersion = System.getProperty("java.version");
- String javafxVersion = System.getProperty("javafx.version");
- //
- System.out.println("javaVersion=" + javaVersion); // JAVA 11 >
- System.out.println("javafxVersion=" + javafxVersion); // JAVAFX14 >
- // создаем корневой узел - используем панель поточной компоновки
- FlowPane pane = new FlowPane();
- // создаем элементы управления
- Button btn1 = new Button("Ok");
- btn1.setText("Ok1");
- TextField textField = new TextField();
- // указываем обработчик события дял кнопки btn1 (используем lambda-выражения)
- btn1.setOnAction((ActionEvent event) -> {
- System.out.println("Press OK BUTTON");
- // получаем источник события
- Object source = event.getSource();
- System.out.println("source=" + source);
- textField.setText("Новый текст!!!");
- //textField.getText()
- });
- // в панель добавляем кнопку
- pane.getChildren().add(btn1);
- //
- Button btn2 = new Button("Exit");
- // указываем обработчик события дял кнопки btn2 (используем ссылку на метод)
- btn2.setOnAction(this::onExitEvent);
- pane.getChildren().add(btn2);
- // Label
- Label l1 = new Label("Text:");
- pane.getChildren().add(l1);
- // Text
- Text text = new Text();
- text.setText("Hello how are you");
- text.setFont(Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 20));
- pane.getChildren().add(text);
- //
- //TextField textField = new TextField();
- textField.setMinWidth(120);
- pane.getChildren().add(textField);
- // создаем сцену (объект типа Scene)
- Scene scene = new Scene(pane, 800, 600);
- // заголовок окна (подмостка)
- stage.setTitle("JavaFX FXDemo1");
- //
- /*
- VBox vbox = new VBox();
- // установка вертикального расстояния между элементами в контейнере
- vbox.setSpacing(10);
- // установка отступов с помощью объекта типа Insets:
- vbox.setPadding(new Insets(15, 20, 10, 10));
- */
- stage.setScene(scene);
- // показ окна на экране
- stage.show();
- }
- //
- private void onExitEvent(ActionEvent t) {
- System.out.println("onExitEvent call>>");
- // Platform.exit - для заверщения FX приложения
- Platform.exit();
- //System.exit(0);
- }
- //
- // переопределить метод init()
- @Override
- public void init(){
- System.out.println("FXDemo1.init>>");
- }
- // переопределить метод stop()
- @Override
- public void stop(){
- System.out.println("FXDemo1.stop>>");
- }
- }
- /*
- Starts the JavaFX runtime, if not already started (see Platform.startup(Runnable) for more information)
- Constructs an instance of the specified Application class
- Calls the init() method
- Calls the start(javafx.stage.Stage) method
- Waits for the application to finish, which happens when either of the following occur:
- the application calls Platform.exit()
- the last window has been closed and the implicitExit attribute on Platform is true
- Calls the stop() method
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement