public class MouseCircle extends Application
1: import javafx.application.Application;
2: import javafx.scene.canvas.Canvas;
3: import javafx.scene.Scene;
4: import javafx.stage.Stage;
5: import javafx.scene.layout.Pane;
6: import javafx.scene.input.MouseEvent;
7: import javafx.scene.shape.Circle;
8: import javafx.scene.paint.Color;
9: import javafx.event.EventHandler;
10:
11:
12: /**
13: This program sets the X/Y coordinates of a Circle to the
14: location of the mouse.
15: */
16: public class MouseCircle extends Application
17: {
18: public static void main(String[] args)
19: {
20: Application.launch(args);
21: }
22:
23: @Override
24: public void start(Stage primaryStage) throws Exception
25: {
26: Pane root = new Pane();
27: root.setPrefSize(400,400);
28:
29: Circle circle = new Circle();
30: circle.setRadius(30);
31: circle.setFill(Color.RED);
32:
33: root.setOnMouseMoved(new EventHandler<MouseEvent>()
34: {
35: @Override
36: public void handle(MouseEvent event)
37: {
38: circle.setCenterX(event.getX());
39: circle.setCenterY(event.getY());
40: }
41: });
42:
43: root.getChildren().add(circle);
44: primaryStage.setScene(new Scene(root));
45: primaryStage.setTitle("Mouse Circle");
46: primaryStage.show();
47: }
48: }