I have a Text and an input field. If the input is correct for the text, the background of the input field should change to green. Then the program should stop for 1 second (and display the input) Then it should generate a new Text with random() and change the color back to white.
input.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.ENTER) {
if(value.equals(input.getText())){
input.setStyle("-fx-background-color: green");
System.out.println("right!");
// now it should wait 1 second
// and display only the input & green background
try{ Thread.sleep(1000);
} catch(InterruptedException i){
throw new Error("interrupted");
}
// random changes the Text and the input will reset
random();
input.setText("");
input.setStyle("-fx-background-color: white");
}
else{
System.out.println("false");
}
}
});
But the problem is, that the background never changes to green. For this one second it is only displaying my input. Then I get a new Text and my background changes to white.
Have you any ideas how to change the background color for this time? Thanks for your answers!
EDIT
It works with PauseTransition instead of Thread so:
PauseTransition wait = new PauseTransition(Duration.seconds(1));
wait.setOnFinished(event -> {
random();
input.setStyle("-fx-background-color: white");
input.setText("");
});
wait.play();