It is actually quite simple. All you have to do is add this bit of code directly in front of yours grid.add(...):
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
moves++;
}
});
Or, equivalently, Java 8 version:
btn.setOnAction((ActionEvent e) -> {moves++;});
( , . , lemme , .)
, , EventHandler . , , . ( ) - for:
EventHandler<ActionEvent> eh = new EventHandler<>() {
@Override public void handle(ActionEvent event) {
moves++;
}
};
:
btn.setOnAction(eh);
EventHandler . , , , ( ) (... it, uh, doesn ). , , , , .