Hello, I am having trouble with EventHandling in JavaFX. I am in the process of making a rhythm game, and I am trying to detect user key presses. There are 4 the user is supposed to input. The keys I am trying to detect are the D, F, J, K keys. I have coded them as four Buttons (b0, b1, b2, b3 respectively), and declared 4 booleans corresponding to each of the buttons.
b0.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
if(event.getCode() == KeyCode.D) {
dPressed = true;
}
}
});
b0.setOnKeyReleased(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
if(event.getCode() == KeyCode.D) {
dPressed = false;
}
}
});
With this code, I intend to use the booleans to check if the user presses one of the keys at a particular time. Eclipse is giving me the error saying that dPressed must be final or effectively final.