Java Code:

public class EventExample extends Application { public void start(Stage primaryStage) { primaryStage.setTitle("Event Example"); FlowPane rootNode = new FlowPane(); final Button button = new Button("my button"); button.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { button.setText("pressed"); } }); rootNode.getChildren().add(button); Scene scene = new Scene(rootNode); primaryStage.setScene(scene); primaryStage.show(); } }