【发布时间】:2019-01-13 05:03:07
【问题描述】:
我运行了一个线程来更新应用程序的打开时间。它运作良好。我已经扩展了服务类。此任务的时间通过 Platform.runLater 更新我的 GUI、textField
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
while (!isCancelled()) {
if (isPause == false) {
try {
Platform.runLater(() -> {
currentTimeInApp = currentTimeInApp + 1;
upPanelController.timeInApp.setText
(currentTimeInApp.toString());
}
});
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
if (isCancelled())
break;
}
}
return null;
}
};
}
我想运行第二个线程来更新 GUI。我不能运行相同的线程。两个独立的线程可以更新 GUI 吗? 互联网上的大多数信息都专门针对一个主题。谢谢你的每一个建议
【问题讨论】: