Added a background task to handle updating the system information
This commit is contained in:
parent
c15472b54f
commit
aa277adcc0
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
16
src/main/java/net/metaunix/tasks/UpdateSystemTask.java
Normal file
16
src/main/java/net/metaunix/tasks/UpdateSystemTask.java
Normal file
@ -0,0 +1,16 @@
|
||||
package net.metaunix.tasks;
|
||||
|
||||
import java.lang.Thread;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
public class UpdateSystemTask extends Task<Void> {
|
||||
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
while (true) {
|
||||
System.out.println("Test");
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user