【发布时间】:2019-05-15 18:09:39
【问题描述】:
我有一个网格窗格,我想让它可见。然后我想暂停程序 2 秒钟,让网格再次不可见。由于某种原因,在我在程序中使用的 thread.sleep 之后网格变得可见。
这一切都发生在按钮点击事件中。
我尝试在 thread.sleep 中移动,将它们放入一个新方法并使用多个睡眠,但没有任何效果。
gameGrid.setVisible(true)
gameGrid.setVisible(false)
按钮事件:
public void handleButtonGo(ActionEvent Event) throws IOException { //On go button press
boolean validation = true;
try {
gameGrid.setVisible(true);
placeShips();
}catch (Exception e){
labelwarning.setText(e.getMessage()); //on error the program will stop trying to place ships and refresh any ships placed so far.
validation = false;
//gameGrid.getChildren().clear();
//BoardSetup();
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
gameGrid.setVisible(false);
}
}
网格在 thread.sleep 之后显示一毫秒。
【问题讨论】:
-
查看 JavaFX 动画类。很多有用的东西。更具体地说是 PauseTransition。
-
了解
TimeLine和PauseTransition。 stackoverflow.com/questions/9966136/…。在PauseTransition示例中,您不需要wait.playFromStart();。
标签: java eclipse events javafx