I'm trying to do "memoryGame" in javaFX. What I'm now dealing with is changing the background of a button, using CSS, twice in one function, after this button was clicked.
In this game I create a GridPane and in each cell I put buttons with pictures, for every picture there are two buttons. On top of it I put another empty buttons. If I click on a button it became transparent, so I can see the picture. Then I clicked another button and the same happens. Now, if the pictures are the same I get one point and the transparency does not change, but if the pictures are different, program waits one second one change both buttons to their primary stage (not transparent).
The problem is that if I change style of a button, wait a second and change it another time, the button does not change its style during this function, but it will happens after the function will ends. So we cannot see the first style, only the last one.
The code I'm sending is simplified version, that 'works' only for one button.
public void changeTransparent(ActionEvent event) {
butCver01.setStyle("-fx-background-color: transparent");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
butCver01.setStyle("-fx-background-color: green");
}
Now when we clicked butCver01, after one second it will change to green.