Example usage for javafx.scene.shape Circle setOnMousePressed

List of usage examples for javafx.scene.shape Circle setOnMousePressed

Introduction

In this page you can find the example usage for javafx.scene.shape Circle setOnMousePressed.

Prototype

public final void setOnMousePressed(EventHandler<? super MouseEvent> value) 

Source Link

Usage

From source file:Main.java

private Circle createCircle(double x, double y, double r, Color color) {
    Circle circle = new Circle(x, y, r, color);

    circle.setCursor(Cursor.HAND);

    circle.setOnMousePressed((t) -> {
        orgSceneX = t.getSceneX();/*from  w  w w.  ja va 2  s.  c  o  m*/
        orgSceneY = t.getSceneY();

        Circle c = (Circle) (t.getSource());
        c.toFront();
    });
    circle.setOnMouseDragged((t) -> {
        double offsetX = t.getSceneX() - orgSceneX;
        double offsetY = t.getSceneY() - orgSceneY;

        Circle c = (Circle) (t.getSource());

        c.setCenterX(c.getCenterX() + offsetX);
        c.setCenterY(c.getCenterY() + offsetY);

        orgSceneX = t.getSceneX();
        orgSceneY = t.getSceneY();
    });
    return circle;
}