Creating a Simple User Interface in JavaFX - Java JavaFX

Java examples for JavaFX:Introduction

Description

Creating a Simple User Interface in JavaFX

Demo Code

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.scene.Group;

public class Main extends Application {

    final Group root = new Group();

    public static void main(String[] args) {
        Application.launch(args);//from  w  w  w . j ava  2 s .co m
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World");
        Scene scene = new Scene(root, 300, 250);
        Button btn = new Button();
        btn.setLayoutX(100);
        btn.setLayoutY(80);
        btn.setText("Hello World");
        btn.setOnAction((event) -> {
                System.out.println("Hello World");
        });
        root.getChildren().add(btn);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

Related Tutorials