Fixed the periodic update
This commit is contained in:
parent
aa277adcc0
commit
2613f8a529
@ -37,11 +37,6 @@ public class App extends Application {
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
HomeController.ust.cancel();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package net.metaunix;
|
||||
|
||||
public class SysInfo {
|
||||
|
||||
public static String osString = "N/a";
|
||||
|
||||
public static String javaVersion() {
|
||||
return System.getProperty("java.version");
|
||||
}
|
||||
|
@ -2,25 +2,29 @@ package net.metaunix.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import net.metaunix.tasks.UpdateSystemTask;
|
||||
|
||||
import net.metaunix.SysInfo;
|
||||
import net.metaunix.services.UpdateSystemInfoService;
|
||||
|
||||
public class HomeController {
|
||||
|
||||
public static UpdateSystemTask ust = new UpdateSystemTask();
|
||||
|
||||
@FXML
|
||||
private Label osInfo;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
SystemInfo si = new SystemInfo();
|
||||
OperatingSystem os = si.getOperatingSystem();
|
||||
osInfo.setText(String.valueOf(os));
|
||||
UpdateSystemInfoService usis = new UpdateSystemInfoService();
|
||||
usis.setOnSucceeded((e) -> {
|
||||
updateLabels();
|
||||
});
|
||||
usis.setPeriod(Duration.seconds(3));
|
||||
usis.start();
|
||||
}
|
||||
|
||||
new Thread(this.ust).start();
|
||||
private void updateLabels() {
|
||||
osInfo.setText(SysInfo.osString);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package net.metaunix.services;
|
||||
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
import net.metaunix.SysInfo;
|
||||
|
||||
public class UpdateSystemInfoService extends ScheduledService<Void> {
|
||||
|
||||
private static int counter = 0;
|
||||
|
||||
@Override
|
||||
protected Task<Void> createTask() {
|
||||
return new Task<>() {
|
||||
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
UpdateSystemInfoService.counter++;
|
||||
SystemInfo si = new SystemInfo();
|
||||
OperatingSystem os = si.getOperatingSystem();
|
||||
SysInfo.osString = String.valueOf(UpdateSystemInfoService.counter) + " " + String.valueOf(os);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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