diff --git a/src/main/java/net/metaunix/App.java b/src/main/java/net/metaunix/App.java index fa0c9b3..94d13c1 100644 --- a/src/main/java/net/metaunix/App.java +++ b/src/main/java/net/metaunix/App.java @@ -11,6 +11,8 @@ import javafx.stage.Stage; import oshi.SystemInfo; import oshi.software.os.OperatingSystem; +import net.metaunix.controllers.HomeController; + /** * JavaFX App @@ -35,6 +37,11 @@ public class App extends Application { stage.show(); } + @Override + public void stop() { + HomeController.ust.cancel(); + } + public static void main(String[] args) { launch(); } diff --git a/src/main/java/net/metaunix/controllers/HomeController.java b/src/main/java/net/metaunix/controllers/HomeController.java index 6e3b78e..b6f275b 100644 --- a/src/main/java/net/metaunix/controllers/HomeController.java +++ b/src/main/java/net/metaunix/controllers/HomeController.java @@ -5,8 +5,12 @@ import javafx.scene.control.Label; import oshi.SystemInfo; import oshi.software.os.OperatingSystem; +import net.metaunix.tasks.UpdateSystemTask; + public class HomeController { + public static UpdateSystemTask ust = new UpdateSystemTask(); + @FXML private Label osInfo; @@ -15,6 +19,8 @@ public class HomeController { SystemInfo si = new SystemInfo(); OperatingSystem os = si.getOperatingSystem(); osInfo.setText(String.valueOf(os)); + + new Thread(this.ust).start(); } } diff --git a/src/main/java/net/metaunix/tasks/UpdateSystemTask.java b/src/main/java/net/metaunix/tasks/UpdateSystemTask.java new file mode 100644 index 0000000..ec15827 --- /dev/null +++ b/src/main/java/net/metaunix/tasks/UpdateSystemTask.java @@ -0,0 +1,16 @@ +package net.metaunix.tasks; + +import java.lang.Thread; +import javafx.concurrent.Task; + +public class UpdateSystemTask extends Task { + + @Override + protected Void call() throws Exception { + while (true) { + System.out.println("Test"); + Thread.sleep(2000); + } + } + +}