javafx – Button – Adding an action listener

Buttons fire action events when they are activated (e.g. clicked, a keybinding for the button is pressed, …).

button.setOnAction(new EventHandler<ActionEvent>() {
    public void handle(ActionEvent event) {
        System.out.println("Hello World!");

If you are using Java 8+, you can use lambdas for action listeners.

button.setOnAction((ActionEvent a) -> System.out.println("Hello, World!"));
// or
button.setOnAction(a -> System.out.println("Hello, World!"));

if you want to reproduce, please indicate the source:
javafx – Button – Adding an action listener - CodeDay