Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javafx.application.Application;
  2. import javafx.application.Platform;
  3. import javafx.concurrent.Task;
  4. import javafx.concurrent.Worker;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Button;
  7. import javafx.stage.Stage;
  8.  
  9. public class TaskExample extends Application {
  10.     @Override
  11.     public void start(final Stage primaryStage) throws Exception {
  12.         String osName = System.getProperty("os.name");
  13.         String javaVersion = System.getProperty("java.version");
  14.         String vmInfo = System.getProperty("java.vm.version") +
  15.                         " (" + System.getProperty("os.arch") + ")";
  16.  
  17.         System.out.println("OS: " + osName);
  18.         System.out.println("Version: " + javaVersion);
  19.         System.out.println("VM Info: " + vmInfo);
  20.         System.out.println("----------------------------------------");
  21.  
  22.         Task<Void> task = new Task<Void>() {
  23.             @Override
  24.             protected Void call() throws Exception {
  25.                 return null;
  26.             }
  27.  
  28.             @Override
  29.             protected void running() {
  30.                 System.out.println("running()");
  31.             }
  32.         };
  33.  
  34.         task.stateProperty().addListener((o, old, newState) -> {
  35.             if(newState == Worker.State.RUNNING) {
  36.                 System.out.println("observed RUNNING");
  37.             }
  38.         });
  39.  
  40.         new Thread(task).start();
  41.  
  42.         Button close = new Button("Close");
  43.         close.setOnAction(event -> Platform.exit());
  44.         primaryStage.setScene(new Scene(close));
  45.         primaryStage.show();
  46.     }
  47.  
  48.     public static void main(String[] args) {
  49.         launch();
  50.     }
  51. }
Advertisement
RAW Paste Data Copied
Advertisement