Listing 15.17 BallPane.java using a thread to animate bouncing ball movements. Listing 1 import javafx.animation.KeyFrame; 2 import
Question:
Listing 15.17 BallPane.java using a thread to animate bouncing ball movements.
Listing
Transcribed Image Text:
1 import javafx.animation.KeyFrame; 2 import javafx.animation.Timeline; 3 import javafx.beans.property.DoubleProperty; 4 import javafx.scene.layout.Pane; 5 import javafx.scene.paint.Color; 6 import javafx.scene.shape.Circle; 7 import javafx.util.Duration; 9 public class BallPane extends Pane { public final double radius = 20; 10 private double x = radius, y = radius; 11 private double dx = 1, dy = 1; 12 13 private Circle circle = new Circle(x, y, radius); private Timeline animation; 14 15 16 17 18 public BallPane() { circle.setFili(Color.GREEN); // Set ball color getChildren().add(circle); // Place a ball into this pane 19 // Create an animation for moving the ball animation = new Timeline( new KeyFrame (Duration.millis(50), e -> moveBall())); animation.setCycleCount (Timeline. INDEFINITE); animation.playO; // Start animation 20 21 22 23 24 25 26 27 public void play() { animation.play(); 28 29 public void pause() { animation.pause(); 31 32 33 34 public void increaseSpeed () { animation.setRate(animation.getRate() + 0.1); 35 36 37 38 39 public void decreaseSpeed () { animation.setRate( animation.getRate() > 0 ? animation.getRate() - 0.1 : 0); 40 41 42 43 44 45 public DoubleProperty rateProperty() { return animation.rateProperty(); 46 47 protected void moveBall() { // Check boundaries if (x < radius || x > getWidth) - radius) { dx *= -1; // Čhange ball move direction 48 49 50 51 52 if (y < radius || y > getHeight() - radius) { dy *= -1; // Change ball move direction 53 54 55 56 // Adjust ball position x += dx; y += dy; circle.setCenterX(x); circle.setCenterY(y); 57 58 59 60 61 62 63 } ANNN NNNONNNNmmm
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 80% (5 reviews)
Program Plan Create add method so that adds one ball to the list when the user clicks on 1 button an...View the full answer
Answered By
Deepak Pal
Hi there! Are you looking for a committed, reliable, and enthusiastic tutor? Well, teaching and learning are more of a second nature to me, having been raised by parents who are both teachers. I have done plenty of studying and lots of learning on many exciting and challenging topics. All these experiences have influenced my decision to take on the teaching role in various capacities. As a tutor, I am looking forward to getting to understand your needs and helping you achieve your academic goals. I'm highly flexible and contactable. I am available to work on short notice since I only prefer to work with very small and select groups of students. Areas of interest: Business, accounting, Project management, sociology, technology, computers, English, linguistics, media, philosophy, political science, statistics, data science, Excel, psychology, art, history, health education, gender studies, cultural studies, ethics, religion. I am also decent with math(s) & Programming. If you have a project you think I can take on, please feel welcome to invite me, and I'm going to check it out!
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
-
Rewrite Listing 15.13 using a thread to animate a flag being raised. Compare the program with Listing 15.13 by setting the delay time to 10 in both programs. Which one runs the animation faster?...
-
Rewrite Programming Exercise 20.5 using a thread to animate bouncing ball movements. The example in Section displays multiple bouncing balls. Extend the example to detect collisions. Once two balls...
-
Rewrite Exercise using a thread to control car racing. Compare the program with Exercise by setting the delay time to 10 in both programs. Which one runs the animation faster? Write a program that...
-
Data Corporation has four employees and provides group term life insurance coverage for all four employees. Coverage is nondiscriminatory and is as follows: a. How much may Data Corporation deduct...
-
During apoptosis, phosphatidylserine (Section 9-1C) undergoes transverse movement (flip-flop). Explain why this could help identify apoptotic cells to phagocytic cells for engulfment and disposal.
-
For the transformer circuit of Fig. 14-11(b), k = 0.96, R 1 = 1.2 , R 2 = 0.3 , X 1 = 20 , X 2 = 5 , Z L = 5.036.87 , and V 2 = 100 0 V. Obtain the coil emfs E 1 and E 2 , and the magnetizing...
-
On February 11, 2009, plaintiff Levista, Inc. (plaintiff) filed against defendant Ranbaxy Pharmaceuticals, Inc. (defendant), pursuant to this Courts diversity jurisdiction under 28 U.S.C. 1332(a),...
-
The CVP income statements shown below are available for Armstrong Company and Contador Company. Instructions (a) Compute the degree of operating leverage for each company and interpret your results....
-
Nina has been with Elora Enterprises for 5 years and is a Customer Service Representative. She earns $2000.00 bi-weekly working 35 hours per week. She does not work any overtime. She has not reached...
-
Ed Klein was the sole shareholder, director, and chief executive officer of The Gun Exchange, Inc., a retail firearms dealership. The inventory of The Gun Exchange had been pledged as security for a...
-
Rewrite Exercise using a thread to control the fan animation. Write a program that displays a running fan, as shown in Figure. Use the?Pause,?Resume,?Reverse?buttons to pause, resume, and reverse fan...
-
Rewrite Programming Exercise using a thread to control the clock animation. Modify Listing, ClockPane.java, to add the animation into this class and add two methods?start()?and?stop()?to start and...
-
Mercury Skateboard Company manufactures skateboards. Several weeks ago, the firm received a special-order inquiry from Venus, Inc. Venus desires to market a skateboard similar to one of Mercurys and...
-
A company has made following estimates if the CFAT of the proposed project. The company uses decision tree analysis to get clear picture of project's cash inflow. The project cost is 1,50,000 and the...
-
Your company plans to produce a new product, a wireless computer mouse. Two machines can be used to make the mouse, Machines A and B. The price per mouse will be $23.00 regardless of which machine is...
-
Over each of the next 4 years, McDougall Corp. expects to sell 56,400 units of its product at a price of $6.00 per unit. Annual fixed costs are expected to be $18,100 and variable costs are estimated...
-
A corporation is 100% owned by an individual. In 2023, it reports business gross receipts of 100,000, interest income of 200,000, and capital gain of 300,000. Assume it has no expenses. WHAT IS THE...
-
The approval authority for O&M construction projects in excess of $750,000, but less than $2,000,000: a. Under Secretary of Defense or designee b. Assistant Secretary of the Army for Acquisition,...
-
In March 1976, Sue made a taxable gift of $200,000. In arriving at the amount of her taxable gift, Sue elected to deduct the $30,000 specific exemption formerly available. In 2014, Sue makes her next...
-
What are technical skills At what level are they most important and why?
-
In our rdt protocols, why did we need to introduce sequence numbers?
-
Consider the rt2.2 receiver in Figure 3.14, and the creation of a new packet in the se1f-ansition (i.e., the transition from the state back to itself) in the Waifor-0-from-below arid the...
-
Visit the Go-sack-N Java applet at the companion Web site. a. Have the source send five packets, and then pause the animation before any of the five packets reach the destination. Then kill the first...
-
In October 20X5, Pollock Company exchanged a used packaging machine having a book value of $240,000 for a new machine and paid a cash difference of $30,000. The market value of the used packaging...
-
Project managers should track the details of their projects to be transparent and manage risks as they arise. What is another benefit of tracking in project management?
-
During 2020, Nike disposed of a machine that had been acquired on January 1, 2014 for a purchase price of $20 million. The machine was being depreciated using the straight-line method, a $4 million...
Study smarter with the SolutionInn App