Modify Listing 20.6, MultipleBallApp.java to assign a random radius between 2 and 20 when a ball is
Question:
Modify Listing 20.6, MultipleBallApp.java to assign a random radius between 2 and 20 when a ball is created. When the - button is clicked, one of largest balls is removed.
Listing
Transcribed Image Text:
1 import javafx.animation.KeyFrame; 2 import javafx.animation.Timeline; 3 import javafx.application.Application; 4 import javafx.beans.property.DoubleProperty; 5 import javafx.geometry.Pos; 6 import javafx.scene.Node; 7 import javafx.stage.Stage; 8 import javafx.scene.Scene; 9 import javafx.scene.control.Button; 10 import javafx.scene.control.Scrol1Bar; 11 import javafx.scene.layout.BorderPane; 12 import javafx.scene.layout.HBox; 13 import javafx.scene.layout.Pane; 14 import javafx.scene.paint.Color; 15 import javafx.scene.shape.Circle; 16 import javafx.util.Duration; 17 18 public class MultipleBounceBall extends Application { 19 @Override // Override the start method in the Application class 20 public void start(Stage primaryStage) { 21 22 23 24 MultipleBallPane ballPane = new MultipleBallPane(); bal1Pane.setStyle("-fx-border-color: yellow"); Button btAdd = new Button("+"); 25 Button btSubtract = new Button("-"); НВох һВох - new HBox(10)%; hBox.getChildren ().addA11(btAdd, btSubtract); hBox.setAlignment (Pos.CENTER); 26 27 28 29 // Add or remove a ball btAdd.setOnAction(e -> ballPane.add()); btSubtract.set0nAction(e -> ballPane.subtract(0); 30 31 32 33 // Pause and resume animation ballPane.setOnMousePressed (e -> ballPane.pause()); ballPane.setOnMouseReleased(e -> bal1Pane.play()); 34 35 36 37 // Use a scrol1 bar to control animation speed Scrol1Bar sbSpeed = new ScrollBar(); sbSpeed.setMax(20); sbSpeed.setValue (10); ballPane.rateProperty().bind(sbSpeed.valueProperty()); 38 39 40 41 42 43 BorderPane pane = new BorderPane(); pane.setCenter (bal1Pane); pane.setTop(sbSpeed); pane.setBottom (hBox); 44 45 46 47 48 // Create a scene and place the pane in the stage Scene scene = new Scene(pane, 250, 150); primaryStage.setTitle("MultipleBounceBall"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage 49 50 51 52 53 54 55 56 private class MultipleBallPane extends Pane { private Timeline animation; 57 58 59 public MultipleBallPane() { // Create an animation for moving the ball animation = new Timeline( new KeyFrame (Duration.millis(50), e -> moveBal10)); animation.setCycleCount(Timeline.INDEFINITE); animation.play(); // Start animation 60 61 62 63 64 65 66 public void add() { Color color = new Color(Math.random(), Math.random(), Math.random(), 0.5); getChildren().add (new Ball(30, 30, 20, color)); 67 68 69 70 71 72 public void subtract() { if (getChildren().size() > 0) { getChildren().remove (getChildren().size() 73 74 75 1); 76 77 78 79 public void play() { animation.play(0; 80 81 82 83 public void pause() {
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (6 reviews)
Program Plan Step 1 The java program creates the two priority queues these queues are ...View the full answer
Answered By
Saud Ur Rehman
Evaluating manufacturing processes by designing and conducting research programs; applying knowledge of product design, fabrication, assembly, tooling, and materials; conferring with equipment vendors; soliciting observations from operators. Developing manufacturing processes by studying product requirements; researching, designing, modifying, and testing manufacturing methods and equipment; conferring with equipment vendors. Keeping equipment operational by coordinating maintenance and repair services; following manufacturer's instructions and established procedures; requesting special service.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Modify Listing 2.10, ComputeChange.java, to display the nonzero denominations only, using singular words for single units such as 1 dollar and 1 penny, and plural words for more than one unit such as...
-
Modify Listing 25.9, BSTAnimation.java, to add three new buttons?Show Inorder, Show Preorder, and Show Postorder?to display the result in a label, as shown in Figure 25.24. You need also to modify...
-
Modify Listing 28.1, TestGraph.java, to create a file representing graph1. The file format is described in Programming Exercise 28.1. Create the file from the array defined in lines 8?21 in Listing...
-
A Hydrogen atom has one proton in the nucleus and one electron in the shell. In a classic model of the atom, in a certain state, this electron is in a circular orbit around the nucleus with an...
-
Greenback Sporting, a retailer of outdoor wear and sporting equipment, is investigating an opportunity to purchase Active Lifestyle Inc. An acquisition is expected to lower overhead costs, improve...
-
The weight of NFL players has increased steadily, gaining up to 1.5 lbs per year since 1942. According to ESPN, the average weight of a National Football League (NFL) player is now 252.8 lbs. Assume...
-
Which of the 11 dimensions identified by Pedler etal. (1991) are currently being pursued in your organisation, or any organisation with which you are familiar? How is this being done? LO8
-
Use Worksheet 8.1. Adam Modine, 43, is a recently divorced father of two children, ages 9 and 7. He currently earns $95,000 a year as an operations manager for a utility company. The divorce...
-
Required information Greenwood Company manufactures two products14,000 units of Product Y and 6,000 units of Product Z. The company uses a plantwide overhead rate based on direct labor-hours. It is...
-
A store maintains data on customers, products and purchase records in three tables: CUSTOMER, PRODUCT, PURCHASE. The store manager wants to know which product is on its maximum discount for each...
-
Define MyPriorityQueue class that extends PriorityQueue to implement the Cloneable interface and implement the clone() method to clone a priority queue.
-
Programming Exercise 7.35 presents a console version of the popular hangman game. Write a GUI program that lets a user play the game. The user guesses a word by entering one letter at a time, as...
-
Prescott Corp. manufactures computer desks in its Seville, Ohio, plant. The company uses activity- based costing to allocate all manufacturing conversion costs (direct labor and manufacturing...
-
Find the derivative. 1 f(x)=(4x3+5x)1/3
-
(5.) The Alden Oil Company buys crude vegetable oil. The refining of this oil results in four products, A, B and C, which are liquids and D, which is heavy grease. The cost of the oil refined in 19_9...
-
Derivative of 4 0 0 0 / x + 4 0 + 0 . 1 x
-
covert the polar equation r = 8 3 c o s ( ) - 4 c o s ( ) t o cartesian
-
(2-4)2 <4 Let F (z) = e +4 4
-
College financial aid offices expect students to use summer earnings to help pay for college. But how large are these earnings? One large university studied this question by asking a random sample of...
-
Find the work done in pumping all the oil (density S = 50 pounds per cubic foot) over the edge of a cylindrical tank that stands on one of its bases. Assume that the radius of the base is 4 feet, the...
-
In Example 11.4 (Figure 11.13), assume the round trip time for a frame is 40 milliseconds. Explain what will happen if we set the time-out in each of the following cases. Figure 11.13 a. 35...
-
In a bit-oriented protocol, should we first unstuff the extra bits and then remove the flags or reverse the process?
-
In Figure 11.11, show what happens in each of the following cases: Figure 11.11 a. The sender is at the ready state and an error-free ACK arrives. b. The sender is at the blocking state and a...
-
True or False: Capitalization rate is used in valuing companies and ignores the effect of debt
-
Question 9 The following information is available for Astrid Ltd and Duncast Ltd. Astrid 15 000 Duncast 15 000 Units produced and sold Rm Rm Revenues 112.5 112.5 55.0 15.0 Variable costs Fixed costs...
-
What is the quoted price of a bond maturing in 12 years with a coupon rate of 9 percent, paid semiannually, that has a YTM of 13 percent? (Please round to the nearest hundredth)
Study smarter with the SolutionInn App