我目前正在使用兩個控制器類。如何在一段時間後關閉舞臺JavaFX
在Controller1中,它創建一個新的階段,打開主要的階段。
Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("Controller2.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
現在一旦這個階段開放,我希望它在關閉之前保持打開狀態約5秒鐘。
在控制器2,我已經試過執行類似
long mTime = System.currentTimeMillis();
long end = mTime + 5000; // 5 seconds
while (System.currentTimeMillis() > end)
{
//close this stage
}
,但我不知道該怎麼把while循環中關閉它。我嘗試了各種各樣,沒有任何作品。
如果您使用這些技術,您將*擁有*在線程中運行它,否則舞臺的內容將不會顯示。此外,您必須將'stage.close()'包裝在'Platform.runLater(...)'中,因爲這必須在FX應用程序線程上執行。使用'PauseTransition'更容易。 – 2014-12-06 17:56:06