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 // Override the start method in the Application class
  8    public void start(Stage primaryStage) {
  9      BallPane ballPane = new BallPane(); // Create a ball pane
 10  
 11      // Pause and resume animation
 12      ballPane.setOnMousePressed(e -> ballPane.pause());
 13      ballPane.setOnMouseReleased(e -> ballPane.play());
 14  
 15      // Increase and decrease animation   
 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      // Create a scene and place it in the stage
 26      Scene scene = new Scene(ballPane, 250, 150);
 27      primaryStage.setTitle("BounceBallControl"); // Set the stage title
 28      primaryStage.setScene(scene); // Place the scene in the stage
 29      primaryStage.show(); // Display the stage
 30      
 31      // Must request focus after the primary stage is displayed
 32      ballPane.requestFocus();
 33    }
 34  
 35    /**
 36     * The main method is only needed for the IDE with limited
 37     * JavaFX support. Not needed for running from the command line.
 38     */
 39    public static void main(String[] args) {
 40      launch(args);
 41    }
 42  }