Example usage for javafx.scene.control Button addEventHandler

List of usage examples for javafx.scene.control Button addEventHandler

Introduction

In this page you can find the example usage for javafx.scene.control Button addEventHandler.

Prototype

public final <T extends Event> void addEventHandler(final EventType<T> eventType,
        final EventHandler<? super T> eventHandler) 

Source Link

Document

Registers an event handler to this node.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);//from w w w  .  ja v  a  2s. com
    stage.setHeight(190);

    VBox vbox = new VBox();
    vbox.setLayoutX(20);
    vbox.setLayoutY(20);

    final Button button1 = new Button("OK");

    button1.addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            System.out.println("mouse entered");
        }
    });

    button1.addEventHandler(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            System.out.println("mouse out");
        }
    });

    vbox.getChildren().add(button1);
    ((Group) scene.getRoot()).getChildren().add(vbox);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Button Sample");
    stage.setWidth(300);//from ww  w.  j a v  a2 s.c om
    stage.setHeight(190);

    VBox vbox = new VBox();
    vbox.setLayoutX(20);
    vbox.setLayoutY(20);

    final Button button1 = new Button("Accept");

    button1.addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            button1.setEffect(shadow);
        }
    });

    button1.addEventHandler(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            button1.setEffect(null);
        }
    });

    vbox.getChildren().add(button1);
    vbox.setSpacing(10);
    ((Group) scene.getRoot()).getChildren().add(vbox);

    stage.setScene(scene);
    stage.show();
}