JavaFX z Arią - powrót do strony głównej

FXML tutorial (21) – element Scene w FXML

Listing21_scene.java
package codes;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.net.URL;
import java.util.Objects;

public class Listing21_scene extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }
    @Override
    public void start(Stage stage) {
        try {
            URL fxmlUrl = this.getClass().getClassLoader().getResource("resources/listing21_scene.fxml");
            Scene scene = FXMLLoader.load(Objects.requireNonNull(fxmlUrl));
            stage.setScene(scene);
            stage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
listing21_scene.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.Scene ?>

<Scene xmlns:fx="http://javafx.com/fxml/1">
    <VBox xmlns:fx="http://javafx.com/fxml">
        <Label fx:id="lab1" text="Twoja decyzja?"/>
        <HBox fx:id="hbox">
            <Button fx:id="but1" text="Tak"/>
            <Button fx:id="but2" text="Nie"/>
            <Button fx:id="but3" text="Anuluj"/>
        </HBox>
    </VBox>
</Scene>

Po uruchomieniu klasy na ekranie zobaczymy:

Okno aplikacji
Okno aplikacji po kliknięciu przycisku ‘Tak’