Source Code : A Task Which Modifies The Scene Graph

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

A Task Which Modifies The Scene Graph

 

import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class Main extends Application {

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

 
    Task<Void> task = new Task<Void>() {
      @Override
      protected Void call() throws Exception {
        for (int i = 0; i < 10; i++) {
          if (isCancelled())
            break;
          final Rectangle r = new Rectangle(10, 10);
          r.setX(10 * i+i);
          Platform.runLater(new Runnable() {
            @Override
            public void run() {
              group.getChildren().add(r);
            }
          });
        }
        return null;
      }
    };
    task.run();
    System.out.println(task.getMessage());

    stage.show();
  }

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



 

   
  

Thank with us