-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRemovePoints.java
More file actions
37 lines (32 loc) · 1.13 KB
/
AddRemovePoints.java
File metadata and controls
37 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class AddRemovePoints extends Application {
private static final double RADIUS = 5;
@Override
public void start(Stage primaryStage) {
Pane pane = new Pane();
pane.setOnMouseClicked(event -> {
if (event.getButton() == MouseButton.PRIMARY) {
Circle circle = new Circle(event.getX(), event.getY(), RADIUS, Color.BLACK);
circle.setOnMouseClicked(e -> {
if (e.getButton() == MouseButton.SECONDARY) {
pane.getChildren().remove(circle);
}
});
pane.getChildren().add(circle);
}
});
Scene scene = new Scene(pane, 600, 400);
primaryStage.setTitle("Add and Remove Points");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}