Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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.
expand button
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
}
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education