Problem

If line 32 in Listing 1 BounceBallControl.java is not in the program, what would happen wh...

If line 32 in Listing 1 BounceBallControl.java is not in the program, what would happen when you press the UP or the DOWN arrow key?

Listing 1 BounceBallControl.java

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 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT