Java Reference
In-Depth Information
eXaMINING the BehaVIOr OF the MetrONOMe1 prOGraM
When the Metronome1 program starts, its appearance should be similar to the screenshot in figure 2-8 . to fully
examine its behavior, perform the following steps.
1.
Observe that of the four buttons on the scene, only the start button is enabled.
2.
Click start. notice that the top of the line moves back and forth, taking one second to travel
each direction. also, observe that the start and resume buttons are disabled and that the
pause and stop buttons are enabled.
3.
Click pause, noticing that the animation pauses. also, observe that the start and pause
buttons are disabled and that the resume and stop buttons are enabled.
4.
Click resume, noticing that the animation resumes from where it was paused.
5.
Click stop, noticing that the animation stops and that the button states are the same as they
were when the program was first started (see step 1).
6.
Click start again, noticing that the line jumps back to its starting point before beginning the
animation (rather than simply resuming as it did in step 4).
7.
Click stop.
Now that you've experienced the behavior of the Metronome1 program, let's walk through the code behind it.
Understanding the Metronome1 Program
Take a look at the code for the Metronome1 program in Listing 2-5, before we discuss relevant concepts.
Listing 2-5. Metronome1Main.java
package projavafx.metronome1.ui;
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
 
Search WWH ::




Custom Search