Write a javaFX program  . . .  (rest of question on picture) Second picture if for what BounceBallControl.java looks like formatted.   **BounceBallControl.java here**   package chapter15; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.input.MouseEvent; public class BounceBallControl extends Application {

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a javaFX program  . . .  (rest of question on picture)

Second picture if for what BounceBallControl.java looks like formatted.

 

**BounceBallControl.java here**

 

package chapter15;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;

public class BounceBallControl extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
BallPane ballPane = new BallPane(); // Create a ball pane

// Pause and resume animation
// ballPane.setOnMousePressed(e -> ballPane.pause());


EventHandler<MouseEvent> handle1 = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
ballPane.pause();
}};
ballPane.setOnMousePressed(handle1);


ballPane.setOnMouseReleased(e ->{
ballPane.play();
System.out.println("mouse released");
});

// Increase and decrease animation
ballPane.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.UP) {
ballPane.increaseSpeed();
}
else if (e.getCode() == KeyCode.DOWN) {
ballPane.decreaseSpeed();
}
});

// Create a scene and place it in the stage
Scene scene = new Scene(ballPane, 400, 300);
primaryStage.setTitle("BounceBallControl"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage

// Must request focus after the primary stage is displayed
ballPane.requestFocus();
}

/**
* The main method is only needed for the IDE with limited
* JavaFX support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
}

1.)
Add a label in the top left corner of the BounceBallControl.java program that shows the speed of the ball.
Add a feature so that if you click on the ball itself with the mouse, it will change to a new random color.
Add a second ball. Make sure it bounces off of the first ball as well as the walls.
Transcribed Image Text:1.) Add a label in the top left corner of the BounceBallControl.java program that shows the speed of the ball. Add a feature so that if you click on the ball itself with the mouse, it will change to a new random color. Add a second ball. Make sure it bounces off of the first ball as well as the walls.
package chapter15;
import javafx.application.Application;
import javafx.event.ActionEvent;
5
import javafx.event.EventHandler;
6
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.input. Keycode;
9
import javafx.scene.input.MouseEvent;
10
public class BounceBallControl extends Application {
@override // Override the start method in the Application class
public void start(Stage primaryStage) {
BallPane bal1Pane = new BallPane(); // Create a ball pane
11
12
13
14
15
// Pause and resume animation
// ballPane.setOnMousePressed(e -> ballPane.pause());
16
17
18
19
EventHandlercMouseEvent> handlel = new EventHandler<MouseEvent> () {
20
21
@Override
22
public void handle (MouseEvent arge) {
23
ballPane.pause();
24
}};
25
ballPane.set0nMousePressed(handle1);
26
27
28
ballPane.setOnMouseReleased (e ->{
29
ballPane.play();
30
System.out.printin("mouse released");
31
});
32
// Increase and decrease animation
ballPane.setonkeyPressed (e -> {
if (e.getCode() == KeyCode.UP) {
ballPane.increaseSpeed ();
33
34
35
36
37
else if (e.getCode() KeyCode. DOWN) {
ballPane.decreaseSpeed ();
38
39
40
41
});
42
43
// Create a scene and place it in the stage
44
Scene scene = new Scene(ballPane, 400, 300);
primarystage. setTitle("BounceBallControl1"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
45
46
47
primarystage. show(); // Display the stage
48
// Must request focus after the primary stage is displayed
ballPane.requestFocus ();
49
50
51
}
52
53
/**
* The main method is only needed for the IDE with limited
* JavaFX support. Not needed for running from the command line.
54
55
56
*/
57
public static void main(String[] args) {
58
launch(args);
59
}
60
}
Transcribed Image Text:package chapter15; import javafx.application.Application; import javafx.event.ActionEvent; 5 import javafx.event.EventHandler; 6 import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.input. Keycode; 9 import javafx.scene.input.MouseEvent; 10 public class BounceBallControl extends Application { @override // Override the start method in the Application class public void start(Stage primaryStage) { BallPane bal1Pane = new BallPane(); // Create a ball pane 11 12 13 14 15 // Pause and resume animation // ballPane.setOnMousePressed(e -> ballPane.pause()); 16 17 18 19 EventHandlercMouseEvent> handlel = new EventHandler<MouseEvent> () { 20 21 @Override 22 public void handle (MouseEvent arge) { 23 ballPane.pause(); 24 }}; 25 ballPane.set0nMousePressed(handle1); 26 27 28 ballPane.setOnMouseReleased (e ->{ 29 ballPane.play(); 30 System.out.printin("mouse released"); 31 }); 32 // Increase and decrease animation ballPane.setonkeyPressed (e -> { if (e.getCode() == KeyCode.UP) { ballPane.increaseSpeed (); 33 34 35 36 37 else if (e.getCode() KeyCode. DOWN) { ballPane.decreaseSpeed (); 38 39 40 41 }); 42 43 // Create a scene and place it in the stage 44 Scene scene = new Scene(ballPane, 400, 300); primarystage. setTitle("BounceBallControl1"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage 45 46 47 primarystage. show(); // Display the stage 48 // Must request focus after the primary stage is displayed ballPane.requestFocus (); 49 50 51 } 52 53 /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. 54 55 56 */ 57 public static void main(String[] args) { 58 launch(args); 59 } 60 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education