1 import javafx.application.Application;
2 import javafx.geometry.Pos;
3 import javafx.scene.Scene;
4 import javafx.scene.control.Button;
5 import javafx.scene.input.KeyCode;
6 import javafx.scene.input.MouseButton;
7 import javafx.scene.layout.HBox;
8 import javafx.scene.layout.BorderPane;
9 import javafx.stage.Stage;
10
11 public class ControlCircleWithMouseAndKey extends Application {
12 private CirclePane circlePane = new CirclePane();
13
14 @Override
15 public void start(Stage primaryStage) {
16
17 HBox hBox = new HBox();
18 hBox.setSpacing(10);
19 hBox.setAlignment(Pos.CENTER);
20 Button btEnlarge = new Button("Enlarge");
21 Button btShrink = new Button("Shrink");
22 hBox.getChildren().add(btEnlarge);
23 hBox.getChildren().add(btShrink);
24
25
26 btEnlarge.setOnAction(e -> circlePane.enlarge());
27 btShrink.setOnAction(e -> circlePane.shrink());
28
29 BorderPane borderPane = new BorderPane();
30 borderPane.setCenter(circlePane);
31 borderPane.setBottom(hBox);
32 BorderPane.setAlignment(hBox, Pos.CENTER);
33
34
35 Scene scene = new Scene(borderPane, 200, 150);
36 primaryStage.setTitle("ControlCircle");
37 primaryStage.setScene(scene);
38 primaryStage.show();
39
40 circlePane.setOnMouseClicked(e -> {
41 if (e.getButton() == MouseButton.PRIMARY) {
42 circlePane.enlarge();
43 }
44 else if (e.getButton() == MouseButton.SECONDARY) {
45 circlePane.shrink();
46 }
47 });
48
49 scene.setOnKeyPressed(e -> {
50 if (e.getCode() == KeyCode.UP) {
51 circlePane.enlarge();
52 }
53 else if (e.getCode() == KeyCode.DOWN) {
54 circlePane.shrink();
55 }
56 });
57 }
58
59
63 public static void main(String[] args) {
64 launch(args);
65 }
66 }