-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseClickPoints.java
67 lines (54 loc) · 2.1 KB
/
MouseClickPoints.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Programmer: Dan Hopp
* Date: 07-APR-2020
* Description: This allows a user to create and remove points in a pane via
mouse clicks. The points wil be small circles. Left-clicking adds a point,
right-clicking within some particular circle (or on its edge) removes the
point.
*/
package lab07;
import javafx.application.Application;
import javafx.scene.Scene;
import static javafx.scene.input.MouseButton.PRIMARY;
import static javafx.scene.input.MouseButton.SECONDARY;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class Hopp_lab7a1 extends Application{
//Main method
public static void main(String[] args){
Application.launch();
}
//Start module
@Override
public void start(Stage PrimaryStage){
//Make blank canvas pane
Pane pane = new Pane();
//tie on-mouse-left-click event to the pane
pane.setOnMouseClicked(e -> {
if(e.getButton() == PRIMARY){
//Random color for the circle
Color color = new Color(Math.random(), Math.random(),
Math.random(), 1);
//Create circle. Get x and y of mouse
Circle circle = new Circle(e.getX(), e.getY(), 25);
circle.setFill(color);
/*On right-click on the circle, delete/remove the circle object
from the pane */
circle.setOnMouseClicked(f -> {
if(f.getButton() == SECONDARY){
circle.setVisible(false);
}
});
//add a circle to that location on the pane
pane.getChildren().add(circle);
}
});
//Display pane
Scene scene = new Scene(pane, 700, 700);
PrimaryStage.setTitle("Dippin' Dots");
PrimaryStage.setScene(scene);
PrimaryStage.show();
}
}