Advertisement
Guest User

Untitled

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