Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage stage) {
        Group root = new Group();
        Scene scene = new Scene(root, 300, 150);
        stage.setScene(scene);
        stage.setTitle("Sample");

        Task<ObservableList<String>> task = new Task<ObservableList<String>>() {
            @Override
            protected ObservableList<String> call() throws Exception {
                updateMessage("message");
                ObservableList<String> results = FXCollections.observableArrayList();
                for (int i = 0; i < 10; i++) {
                    if (isCancelled())
                        break;
                    results.add("");
                    updateProgress(i, 100);
                }
                return results;
            }
        };
        task.run();
        System.out.println(task.getMessage());

        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}