Question: 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
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?
Listing


1 import javafx.animation.PathTransition; 2 import javafx.application. Application; 3 import javafx.scene.Scene; 4 import javafx.scene.image. ImageView; 5 import javafx.scene.layout.Pane; 6 import javafx.scene.shape.Line; 7 import javafx.stage.Stage; 8 import javafx.util.Duration; 10 public class FlagRisingAnimation extends Application { 11 @Override // Override the start method in the Application class 12 public void start(Stage primaryStage) { 13 14 15 16 17 18 19 20 21 // Create a pane Pane pane - new Pane (); // Add an image view and add it to pane ImageView imageView = new ImageView("image/us.gif"); pane.getChildren().add(imageView); // Create a path transition PathTransition pt = new PathTransition(Duration.millis(10000), 22 new Line(100, 200, 100, 0), imageView); 24 pt.play(); // Start animation pt.setCycleCount(5); 26 // Create a scene and place it in the stage Scene scene - new Scene (pane, 250, 200); primarystage.setTitle("FlagRisingAnimation"); // Set the stage title primaryStage.setScene (scene); // Place the scene in the stage primaryStage.show(); // Display the stage 28 29 31 32 }
Step by Step Solution
3.42 Rating (168 Votes )
There are 3 Steps involved in it
Program Plan Refer to class FlagRisingAnimation from Listing 1513 and add delay in it using delayProperty function and run it Create a new class FlagR... View full answer
Get step-by-step solutions from verified subject matter experts
