import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.event.EventHandler; import javafx.event.ActionEvent; public class Knapper extends Application { @Override public void start(Stage stage) { HBox root = new HBox(); Button knapp = new Button("Knapp 1"); knapp.setOnAction(new Knappebehandler()); Button knapp2 = new Button("Knapp 2"); knapp2.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { System.out.println("Dette kommer fra en anonym klasse!"); } }); Button knapp3 = new Button("Knapp 3"); knapp3.setOnAction(e -> System.out.println("Lambda!")); root.getChildren().addAll(knapp, knapp2, knapp3); stage.setScene(new Scene(root)); stage.show(); } private class Knappebehandler implements EventHandler { @Override public void handle(ActionEvent e) { System.out.println("Vanlig knappebehandler"); } } }