1 import javafx.application.Application;
2 import javafx.stage.Stage;
3 import javafx.scene.Scene;
4 import javafx.scene.input.KeyCode;
5
6 public class BounceBallControl extends Application {
7 @Override
8 public void start(Stage primaryStage) {
9 BallPane ballPane = new BallPane();
10
11
12 ballPane.setOnMousePressed(e -> ballPane.pause());
13 ballPane.setOnMouseReleased(e -> ballPane.play());
14
15
16 ballPane.setOnKeyPressed(e -> {
17 if (e.getCode() == KeyCode.UP) {
18 ballPane.increaseSpeed();
19 }
20 else if (e.getCode() == KeyCode.DOWN) {
21 ballPane.decreaseSpeed();
22 }
23 });
24
25
26 Scene scene = new Scene(ballPane, 250, 150);
27 primaryStage.setTitle("BounceBallControl");
28 primaryStage.setScene(scene);
29 primaryStage.show();
30
31
32 ballPane.requestFocus();
33 }
34
35
39 public static void main(String[] args) {
40 launch(args);
41 }
42 }