【发布时间】:2018-08-13 09:58:59
【问题描述】:
我试图在满足某个条件时弹出一个窗口,但是在满足条件时。窗口没有打开。我正在使用 Thread.sleep
代码:
public void grow() {
Thread thread = new Thread(() -> {
try {
Thread.sleep(this.harvestTime);
if(water >= waterNeeded && fertelizer >= fertelizerNeeded) {
this.harvest = true;
AlertBox.display("CROP ALERT","A SEED HAS FINISHED GROWING");
Thread.sleep(60000);
if(harvest == true) {
withered = true;
harvest = false;
AlertBox.display("ALERT", "FAILED TO HARVEST A CROP. IT BECAME WITHERED!");
}
}
else {
this.withered = true;
}
} catch (Exception e) {
}
});
thread.start();
}
【问题讨论】:
-
GUI 框架(不仅仅是 Java,其他的也一样)通常不能在线程中工作,您必须将 GUI 活动提交给 GUI 线程。
标签: java multithreading javafx