Example usage for javafx.scene Scene addEventHandler

List of usage examples for javafx.scene Scene addEventHandler

Introduction

In this page you can find the example usage for javafx.scene Scene 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 scene.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");

    // Register an event handler for a single node and a specific event type
    scene.addEventHandler(DragEvent.DRAG_ENTERED, new EventHandler<DragEvent>() {
        public void handle(DragEvent e) {
            System.out.println("drag enter");
        }//from w ww  . j  ava2  s  .  co  m
    });

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");

    // Define an event handler
    EventHandler handler = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Handling event " + event.getEventType());
            event.consume();/*w w w .jav  a2 s .  c  om*/
        }
    };
    scene.addEventHandler(DragEvent.DRAG_EXITED, handler);

    scene.addEventHandler(MouseEvent.MOUSE_DRAGGED, handler);

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:org.openbase.display.DisplayView.java

private void init(final Stage primaryStage) throws InterruptedException, InitializationException {

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override/* w w  w  .  j  a  v a 2  s .c om*/
        public void run() {
            Platform.exit();
        }
    });

    try {
        // platform configuration
        Platform.setImplicitExit(false);
        primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
        this.primaryStage = primaryStage;

        Scene scene = new Scene(cardsPane);

        // configure hide key combination
        final KeyCombination escapeKey = new KeyCodeCombination(KeyCode.ESCAPE);
        scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {

            @Override
            public void handle(KeyEvent event) {
                if (escapeKey.match(event)) {
                    try {
                        setVisible(false);
                    } catch (CouldNotPerformException ex) {
                        ExceptionPrinter.printHistory(
                                new CouldNotPerformException("Could not execute key event!", ex), logger);
                    }
                }
            }
        });

        primaryStage.setScene(scene);

        try {
            broadcastServer = new DisplayServer(this);
            broadcastServer.init(JPService.getProperty(JPBroadcastDisplayScope.class).getValue());
            broadcastServer.activate();
        } catch (JPServiceException | CouldNotPerformException ex) {
            throw new CouldNotPerformException("Could not load display server!", ex);
        }

        try {
            displayServer = new DisplayServer(this);
            displayServer.init(JPService.getProperty(JPDisplayScope.class).getValue());
            displayServer.activate();
        } catch (JPServiceException | CouldNotPerformException ex) {
            throw new CouldNotPerformException("Could not load display server!", ex);
        }
        this.htmlLoader.init(getScreen());
    } catch (CouldNotPerformException ex) {
        throw new InitializationException(this, ex);
    }
}