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.
-
the development of a promotion plan?
-
What would be the main arguments for and against introducing legislation that is similar to the Ontario Pay Equity Act in the UK? LO9
-
The Sorter Company purchased equipment for $200,000 on January 2, 2007. The equipment has an estimated service life of eight years and an estimated residual value of $20,000. Required Compute the...
-
Finch Publications established the following standard price and costs for a hardcover picture book that the company produces. $ Standard price and variable costs Sales price Materials cost Labor cost...
-
Assume that you were recently hired as assistant to Jerry Lehman, financial VP of Coleman Technologies. Your first task is to estimate Colemans cost of capital. Lehman has provided you with the...
-
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...
-
Describe key characteristics and graphs of various cost behaviors
-
Ch 3: Forecasting: Tracking Signals, Mad, Exponential Smoothing, Control Charts Media Consultants (10 Pts). Media Consultants uses proven techniques to measure forecast accuracy and to determine when...
-
Question 2 What is the energy (in joules) of the photon absorbed by a hydrogen atom to cause a ground-state electron to move to the n = 3 energy level? Record your answer in scientific notation to 3...
-
K ints: 0 of 3 Save The height of women ages 20-29 is normally distributed, with a mean of 64 inches. Assume = 2.7 inches. Are you more likely to randomly select 1 woman with a height less than 65.2...
-
CASE 11-23 Balanced Scorecard LO11-4 Haglund Department Store is located in the downtown area of a small city. While the store had been profitable for many years, it is facing increasing competition...
-
0.1 points Sert Avne Your monthly Cable/Internet payment increases to $104 for the month of March and on. What is the new annual total you pay for Cablemed $1,178 $1,192 $1,206 $1,220
-
In which of the following situations would it be appropriate to use a Normal distribution to approximate probabilities for a binomial distribution with the given values of n and p? a. n = 10, p = 0.5...
-
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...
-
Mears Production Company makes several products and sells them for an average price of $70. Mears' accountant is considering two different approaches to estimating the firm's total monthly cost...
-
A fost-growing firm recently paid a dividend of $0.20 per share. The dividend is expected to increase at a 20 percent rate for the next three years. Afterwards, a more stable 11 percent growth rate...
-
What image does it intend to convey? What messages are being communicated to the shareholders? Assess the financial strength of the company and list three audit risk factors you have identified which...
Study smarter with the SolutionInn App