You must hang an event handler:
public class CustomButton extends Button implements EventHandler<MouseEvent> { public CustomButton() { super("myButton"); } @Override public void handle(MouseEvent event) { if (event.getEventType() == MouseEvent.MOUSE_CLICKED){ setText("hello"); System.out.println("button pressed"); } } } main:
public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Stage stage = primaryStage; stage.setTitle("Simple Application"); stage.setScene(InitScene()); stage.show(); } private Scene InitScene(){ Group root = new Group(); Scene myScene = new Scene(root, 300, 300); root.getChildren().add (new CustomButton()); return myScene; } public static void main(String... args){ launch(args); } }
Problem: when you press a button, absolutely nothing happens.