Buttons fire action events when they are activated (e.g. clicked, a keybinding for the button is pressed, ...).
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
...