Java Reference
In-Depth Information
Designer. From Chapter 2, there were five main graphical objects: BlueSky ,
DarkSky , Moon , Sun , SunBurst , and Totality . These are used in both anima-
tions, but with different implementations.
JavaFX Shapes
This example implements the total eclipse only using JavaFX shapes and effects.
The first task is to create custom nodes for each of the main graphical objects:
BlueSky , DarkSky , Moon , Sun , SunBurst , and Totality . Each of these objects
extends javafx.scene.CustomNode and implements the abstract function create()
from CustomNode .
BlueSky and DarkSky are both rectangular shapes. BlueSky has a LinearGradient
fill pattern from light skyblue to white. DarkSky has a black fill pattern with ran-
dom pattern of circles that represent stars. Listing 7.6 shows the implementation
for BlueSky .
Listing 7.6
BlueSky
public class BlueSky extends CustomNode {
public var width:Number = 600;
public var height: Number = 600;
public override function create(): Node {
Rectangle {
width: bind width
height: bind height
fill: LinearGradient {
endY: 1.0
endX: 0.0
stops: [
Stop {
offset: 0.0
color: Color.LIGHTSKYBLUE
},
Stop {
offset: 1.0
color: Color.WHITE
},
]
}
}
}
}
DarkSky is shown in Listing 7.7.
 
 
Search WWH ::




Custom Search