Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.concurrent.Service;
- import javafx.concurrent.Task;
- import javafx.concurrent.Worker;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.stage.Stage;
- public class ServiceExample extends Application {
- @Override
- public void start(final Stage primaryStage) throws Exception {
- String osName = System.getProperty("os.name");
- String javaVersion = System.getProperty("java.version");
- String vmInfo = System.getProperty("java.vm.version") +
- " (" + System.getProperty("os.arch") + ")";
- System.out.println("OS: " + osName);
- System.out.println("Version: " + javaVersion);
- System.out.println("VM Info: " + vmInfo);
- System.out.println("----------------------------------------");
- Service<Void> service = new Service<Void>() {
- @Override
- protected Task<Void> createTask() {
- return new Task<Void>() {
- @Override
- protected Void call() throws Exception {
- return null;
- }
- };
- }
- @Override
- protected void running() {
- System.out.println("running()");
- }
- };
- service.stateProperty().addListener((o, old, newState) -> {
- if(newState == Worker.State.RUNNING) {
- System.out.println("observed RUNNING");
- }
- });
- service.start();
- Button close = new Button("Close");
- close.setOnAction(event -> Platform.exit());
- primaryStage.setScene(new Scene(close));
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement