Example usage for javafx.scene.shape Circle Circle

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

Introduction

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

Prototype

public Circle(double centerX, double centerY, double radius, Paint fill) 

Source Link

Document

Creates a new instance of Circle with a specified position, radius and fill.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");

    final Circle circ = new Circle(40, 30, 20, Color.RED);
    final Group root = new Group(circ);
    final Scene scene = new Scene(root, 400, 300);

    primaryStage.setScene(scene);/*from  w ww  . j  av a 2  s  .co  m*/
    primaryStage.show();
}

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 .  java 2  s  .co  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;
}