Write a program that displays a flag rising up, as shown in Figure 15.14. As the national
Question:
Write a program that displays a flag rising up, as shown in Figure 15.14. As the national flag rises, play the national anthem. (You may use a flag image and anthem audio file from Listing 16.15.)
The animation simulates a flag rising.
Listing
Transcribed Image Text:
FagRising Animation O| FlagRisingAnimation FagRisingAnimation х 1 import javafx.application.Application; 2 import javafx.collections.FXCollections; 3 import javafx.collections.Observablelist; 4 import javafx.stage.Stage; 5 import javafx.geometry.Pos; 6 import javafx.scene. Scene; 7 import javafx.scene.control.Button; 8 import javafx.scene.contro1.ComboBox; 9 import javafx.scene.control.Label; 10 import javafx.scene.image.Image; 11 import javafx.scene.image.ImageView; 12 import javafx.scene.layout.BorderPane; 13 import javafx.scene.layout. HBox; 14 import javafx.scene.media.Media; 15 import javafx.scene.media.MediaPlayer; 16 17 public class FlagAnthem extends Application { 18 19 20 21 22 private final static int NUMBER_OF_NATIONS private final static String URLBase = "http://cs.armstrong.edu/liang/common"; private int currentIndex = 0; 7; @0verride // Override the start method in the Application class public void start(Stage primaryStage) { Image [] images = new Image [NUMBER_OF_NATIONS]; MediaPlayer[] mp = new MediaPlayer[NUMBER_OF_NATIONS]; 23 24 25 26 27 28 29 30 31 32 33 // Load images and audio for (int i = 0; i < NUMBER_OF_NATIONS; i++) { images [i] mp[i] = new MediaPlayer(new Media( URLBase + "/audio/anthem/anthem" + i + ".mp3")); = new Image (URLBase + "/image/flag" + i + ".gif"); 34 Button btPlayPause - new Button (">"); btPlayPause.setOnAction (e -> { if (btPlayPause.getText().equals(">")) { btPlayPause.setText ("||"); mp[currentIndex]. pause(); } else { btPlayPause.setText(">"); mp[currentIndex].play(); 35 36 37 38 39 40 41 42 43 44 }); 45 46 ImageView imageView = new ImageView(images[currentIndex]); ComboBox
FagRising Animation O| FlagRisingAnimation FagRisingAnimation х 1 import javafx.application.Application; 2 import javafx.collections.FXCollections; 3 import javafx.collections.Observablelist; 4 import javafx.stage.Stage; 5 import javafx.geometry.Pos; 6 import javafx.scene. Scene; 7 import javafx.scene.control.Button; 8 import javafx.scene.contro1.ComboBox; 9 import javafx.scene.control.Label; 10 import javafx.scene.image.Image; 11 import javafx.scene.image.ImageView; 12 import javafx.scene.layout.BorderPane; 13 import javafx.scene.layout. HBox; 14 import javafx.scene.media.Media; 15 import javafx.scene.media.MediaPlayer; 16 17 public class FlagAnthem extends Application { 18 19 20 21 22 private final static int NUMBER_OF_NATIONS private final static String URLBase = "http://cs.armstrong.edu/liang/common"; private int currentIndex = 0; 7; @0verride // Override the start method in the Application class public void start(Stage primaryStage) { Image [] images = new Image [NUMBER_OF_NATIONS]; MediaPlayer[] mp = new MediaPlayer[NUMBER_OF_NATIONS]; 23 24 25 26 27 28 29 30 31 32 33 // Load images and audio for (int i = 0; i < NUMBER_OF_NATIONS; i++) { images [i] mp[i] = new MediaPlayer(new Media( URLBase + "/audio/anthem/anthem" + i + ".mp3")); = new Image (URLBase + "/image/flag" + i + ".gif"); 34 Button btPlayPause - new Button (">"); btPlayPause.setOnAction (e -> { if (btPlayPause.getText().equals(">")) { btPlayPause.setText ("||"); mp[currentIndex]. pause(); } else { btPlayPause.setText(">"); mp[currentIndex].play(); 35 36 37 38 39 40 41 42 43 44 }); 45 46 ImageView imageView = new ImageView(images[currentIndex]); ComboBox cboNation = new ComboBox<> (); Observablelist items = ("Denmark", "Germany", "China", "India", "Norway", "UK", "US"); cboNation.getItems ().addA11(items); cboNation.setValue(items.get(0)); cboNation.setOnAction(e -> { mp[currentIndex].stop(); currentIndex = items.indexOf(cboNation.getValue()); imageView.setImage(images [currentIndex]); mp [currentIndex].play(); }); 47 FXCo1lections.observableArrayList 48 49 50 51 52 53 54 55 56 57
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 80% (10 reviews)
Program Plan The program creates an interface that displays a flag rising up that is with reference ...View the full answer
Answered By
Lynn Wathigo
I am passionate about teaching,especially subjects in the humanities field. I enjoy reading and creative writing, one of my favorite areas to tutor.
I look forward to tutoring a student with similar interests, and helping the improve their grades.
Thank you.
0.00
0 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
-
Write a program that displays a bean machine introduced in Exercise, as shown in Figure. The bean machine, also known as a quincunx or the Galton box, is a device for statistics experiments named...
-
Write a program that displays a running fan, as shown in Figure 15.33c. Use the Pause, Resume, Reverse buttons to pause, resume, and reverse fan running. Pause Reverse Resume (c)
-
Write a program that displays a circle of radius 10 pixels filled with a random color at a random location on a pane, as shown in Figure 15.29b. When you click the circle, it disappears and a new...
-
Craps is a dice game in which two fair dice are cast. If the roller shoots a 7 or 11 on the rst roll, he or she wins. If the roller shoots a 2, 3, or 12 on the rst roll, he or she loses. (a) Compute...
-
Branger Ltd. has the choice of issuing floating-rate debt at LIBOR + 1% or fixed-rate debt at Swaps 6%. Likewise, Creeson Plastics can issue floating-rate debt at LIBOR + 2.5% or fixed-rate debt at...
-
The optical department at Costco serves customers on a first-come-first-serve basis. Suppose the time between customer arrivals follows the exponential distribution. Historical data indicates that...
-
Think about your own experiences at work or those of close friends and family. What were the key factors that affected decisions to leave a particular job? What, if anything, could the employer have...
-
The comparative statements of Larker Tool Company are presented below. All sales were on account. Instructions Compute the following ratios for 2013. (Weighted-average common shares in 2013 were...
-
A young graduate wants to own the latest greatest cell phone plan trom Horton Wireless. The graduate purchases a plan that costs $286 60 per month Let's assure that the cost of this plan is constant...
-
In a controlled laboratory experiment, scientists at the University of Minnesota discovered that 25% of a certain strain of rats subjected to a 20% coffee bean diet and then force-fed a powerful...
-
Listing 16.4, ComboBoxDemo.java, gives a program that lets the user view a country?s flag image and description by selecting the country from a combo box. The description is a string coded in the...
-
Write a program that simulates four cars racing, as shown in Figure 16.47b. You can set the speed for each car, with maximum 100. 2 Car 3: 10 Car 4: Car 1: Car 2: 5 (b)
-
A cylinder of compacted scrap metal measuring 2 m in length and 0.5 m in diameter is suspended from a spring scale at a location where the acceleration of gravity is 9.78 m/s2. If the scrap metal...
-
What is the discount rate? PV = 7 0 0 ; t = 5 year period; FV = 1 0 0 0
-
How is planning illustrated in this case story? How is strategic management illustrated in this case story? The new CEO stated that the CEO's job is to give employees a point of view. Explain what...
-
Explain the Following Questions: 1. What essential characteristics exist in a proper understanding of "personal mastery," so that as an individual achieves greater progress in this discipline, they...
-
Few people want to eat discolored french fries. Potatoes are kept refrigerated before being cut for french fries to prevent spoiling and preserve flavor. But immediate processing of cold potatoes...
-
Part 3 of 4 Points: 0.49 of 1 Compute P(X) using the binomial probability formula. Then determine whether the normal distribution can be used to estimate this probability. If so, approximate P(X)...
-
The researchers report that the results were statistically significant at the 1% level. Which of the following is the most appropriate conclusion? a. Because the P-value is less than 1%, fail to...
-
Southwestern Punch was made by Frutayuda, Inc. and sold in 12-ounce cans to benefit victims of Hurricane Zero. The mean number of ounces placed in a can by an automatic fill pump is 11.7 with a...
-
Another useful parameter in a LAN is the bit length of the medium (L b ), which defines the number of bits that the medium can hold at any time. Find the bit length of a LAN if the data rate is 100...
-
Based on Figure 12.15, how do we interpret success in an Aloha network? Figure 12.15 Station has a frame to send K= 0 Legend K: Number of attempts Tg: Backoff time IFS: Interframe Space RTS: Request...
-
We have defined the parameter a as the number of frames that can fit the medium between two stations, or a = (T p )/(T fr ). Another way to define this parameter is a = L b /F b , in which L b is the...
-
Adelphi Company has budgeted activity for March to reflect net income $115,000. All sales are credit sales. Receivables are planned to increase (decrease -) by $21,000 payables to increase (decrease...
-
Use the following information to construct an income statement. Interest = $25,000; Sales = $950,000; Income tax rate = 25%; Selling and marketing expenses = $160,000; General and administrative...
-
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...
Study smarter with the SolutionInn App