I have a grid Pane which I want to make visible. I want to then pause the program for 2 seconds and make the grid invisible again. For some reason the grid becomes visible after the thread.sleep that I use in my program.
This all happens inside a button click event.
I tried moving around the thread.sleep, putting them in a new method and using multiple sleep but nothing worked.
gameGrid.setVisible(true)
gameGrid.setVisible(false)
Button event:
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);
}
}
The grid is displayed for a millisecond after the thread.sleep.