Java Reference
In-Depth Information
15 Label lblCurrentTime = new Label(timeString);
16
17 // Place clock and label in border pane
18 BorderPane pane = new BorderPane();
19 pane.setCenter(clock);
20 pane.setBottom(lblCurrentTime);
21 BorderPane.setAlignment(lblCurrentTime, Pos.TOP_CENTER);
22
23 // Create a scene and place it in the stage
24 Scene scene = new Scene(pane, 250 , 250 );
25 primaryStage.setTitle( "DisplayClock" ); // Set the stage title
26 primaryStage.setScene(scene); // Place the scene in the stage
27 primaryStage.show(); // Display the stage
28
29
pane.widthProperty().addListener(ov ->
create a listener
set a new width for clock
30
clock.setW(pane.getWidth())
31
);
32
33
pane.heightProperty().addListener(ov ->
create a listener
set a new height for clock
34
clock.setH(pane.getHeight())
35
);
36 }
37 }
The program is identical to Listing 14.19 except that you added the code in lines 29-35 to
register listeners for resizing the clock pane upon a change of the width or height of the scene.
The code ensures that the clock pane size is synchronized with the scene size.
15.19
What would happen if you replace pane with scene or primaryStage in lines 29
and 33?
Check
Point
15.11 Animation
JavaFX provides the Animation class with the core functionality for all animations.
Suppose you want to write a program that animates a rising flag, as shown in Figure 15.14.
How do you accomplish the task? There are several ways to program this. An effective
one is to use the subclasses of the JavaFX Animation class, which is the subject of this
section.
Key
Point
VideoNote
Animate a rising flag
F IGURE 15.14
The animation simulates a flag rising.
The abstract Animation class provides the core functionalities for animations in JavaFX,
as shown in Figure 15.15. Many concrete subclasses of Animation are provided in JavaFX.
This section introduces PathTransition , FadeTransition and Timeline .
 
 
Search WWH ::




Custom Search