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: 100% (4 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 Environmental Protection Agency (EPA) performs extensive tests on all new car models to determine their mileage ratings. The results of 100 EPA tests on a certain new car model are displayed in...
-
Determine whether each of the following is true or false. In each case, assume \(P\) is located at \(t=0\) and \(F\) is located at \(t=n\), and the \(A\) s are spread uniformly over the planning...
-
For each of the unrelated transactions described below, present the entry(ies) required to record each transaction. 1. Coyle Corp. issued $10,000,000 par value 10% convertible bonds at 99. If the...
-
. Conduct research and review the pricing models for Amazon Web Services and Microsoft's Azure. . How are they similar and how are they different?
-
Diane Leto, controller at Dewey Yaeger Pharmaceutical Industries, a public company, is currently preparing the calculation for basic and diluted earnings per share and the related disclosure for...
-
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...
-
Find a basis for the solution set of this system. x1 - 4x2 + 3x3 - x4 = 0 2x1 - 8x2 + 6x3 - 2x4 = 0
-
ABC company have forecast approximately 10 million sales for the coming year. They have decided to allocate 200,000 (2% of turnover) to marketing. Which budget setting method are they using?
-
where the tax base of an asset exceeds its carrying amount in the statement of financial position, what term describes the difference?
-
What would a labor economist argue related to employer-provided health insurance?
-
Gather AB notes (Part II), and lit rev analysis (Part III), and write an outline for a literature review. Lit rev will also report on what is known about a certain topic related to the question you...
-
GOFAST wants to buy a $120,000 car and have it paid off in 5 years by paying in equal monthly instalments including both the principal amount and accumulated interest. Assume the rate is 9 per cent...
-
You are given the following information about Sasha Company's inventory for the month of April. Instructions (a) Calculate the cost of goods available for sale and the number of units of ending...
-
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...
-
Write a program that accepts a phone number of the form +1(xxx)-XXX-XXXX where x is a digit, and displays the sum of all digits in the phone number. Example (user's input in red, output in blue)...
-
4. (25 points) The reverse of a directed graph G is another directed graph GR with the same vertex set with the property that if (u, v) is an edge in G then (v, u) is an edge in GR. Consider the...
-
2. (25 points) The Fibonacci numbers Fo, F1,..., are defined by Fo 0, F11, Fn = Fn-1 + Fn-2 Use induction to prove that: (a) Use induction to prove that Fn 20.5n for n 6 (b) Use induction to prove...
Study smarter with the SolutionInn App