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.
-
Consider the series (a) Determine the convergence or divergence of the series for x = 1. (b) Determine the convergence or divergence of the series for x = 1/e. (c) Find the positive values of for...
-
Janet Agnew and Buford Franco are partners in a business. Each partner withdraws assets during May of the current year. Instructions: Journalize the transactions using page 12 of a cash payments...
-
The Jeffrey Getelman Publishing Company maintains an online database of subscriber records, which it uses for preparing magazine labels, billing renewals, and so forth. New subscription orders and...
-
$3,025,000 Pate, which choice shall you choose and why? received immediately. Suppose you 9. What's the rate of return you will have if you invest in an asset with the following expected cash flows...
-
Consider the following 0x86 program: .data array DWORD 1,2,3,4,5,6,7,8,9 aravSize -(S-array)/4 ; array .code main PROC mov ecx,arraySize-1 mov esi.OFFSET array L1: mov eax. [esi] sda mov bx,2 idiv bx...
-
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...
-
The managers of a company are planning to manufacture more product than is needed for expected sales for the coming year. What effect will this have on operating income under (a) The absorption...
-
Fraction scavenger hunt: Create a list of objects around your house that can be divided into fractions (e.g., pizza slices, candy bars). Find and record the fractions associated with each object.
-
Briefly summarize the approaches to the nature and nurture controversy. Provide two examples of nature and two examples of nurture and explain their influence on your own development. Evaluate the...
-
Cap Inc., a U.S. manufacturer, purchased computers from a German seller for 4,000,000, payment to be made in 1 year. . Today's spot rate of the Euro is $1.38, and the 1 year forward rate is $1.36....
-
How does Gabriel Garca Mrquez employ magical realism as a literary device in "One Hundred Years of Solitude," and what effect does it have on the narrative's portrayal of historical events and...
-
This is Mrs. Riley. She has just been asked to take over a class of third graders who are very energetic and have tried the patience of many teachers. In fact, Mrs. Riley is the third teacher to take...
-
William and Maria Smith are a married couple filing jointly. They have no children and report the following items in 2016: Taxable...
-
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...
-
Problem 5-11 NPV versus IRR Consider the following cash flows on two mutually exclusive projects for the Bahamas Recreation Corporation (BRC). Both projects require an annual return of 14 percent....
-
Susan is trying to decide whether or not to attend college during the next 12-week session. She has the following options: 1. Attend college full-time at a cost of $1,200. 2. Attend college part-time...
-
At a computer manufacturing company, the actual size of computer chips is normally distributed with a mean of 1 centimeter and a standard deviation of 0.1 centimeter. A random sample of 12 computer...
Study smarter with the SolutionInn App