我目前正在使用两个控制器类。
在Controller1中,它创建了一个新阶段,在主阶段的顶部打开。
Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("Controller2.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
现在,一旦这个阶段开启,我希望它在关闭之前保持开启大约5秒钟。在Controller2中,我尝试实现了类似以下的内容。
long mTime = System.currentTimeMillis();
long end = mTime + 5000; // 5 seconds
while (System.currentTimeMillis() > end)
{
//close this stage
}
但是我不知道在while循环内部要放什么才能结束它。我尝试了各种方法,但都没有成功。
Platform.runLater(...)
将stage.close()
包装起来,因为它必须在FX应用程序线程上执行。使用PauseTransition
更容易些。 - James_D