@Override
public void start(Stage primaryStage) {
Circle magnet = createCircle(50,50,Color.RED);
StackPane root = new StackPane();
root.getChildren().add(magnet);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
private Circle createCircle(double x, double y, Color color) {
final Circle c = new Circle(x, y, 25);
c.setFill(color);
c.setOnMouseDragged(new EventHandler
@Override
public void handle(MouseEvent event) {
c.relocate(event.getSceneX() - c.getRadius(), event.getSceneY() - c.getRadius());
}
});
return c;
}
References
http://stackoverflow.com/questions/10530829/javafx-drag-and-drop-moving-icon
No comments:
Post a Comment