Java Reference
In-Depth Information
In addition to specifying a
Text
node with a
DistantLight
effect, Listing 6.2
also includes a black
Rectangle
node, which serves as a background to better
contrast the lighting effect. By wrapping the content inside a
run()
function as
defined in the preceding code, you can use the Design Preview feature of Net-
Beans to make changes to your code and interactively see how those changes
affect your display.
Adding a run() Function to Your Source Files
It is not uncommon for Java programmers to add
main()
methods inside their class
definitions. Even though many individual classes are never meant to be run by
themselves, including a
main()
method gives the developer an opportunity to test
and debug a class separate from the whole application. JavaFX has a somewhat
analogous capability with the
run()
function. By placing a
run()
function at the
script level in your source, which follows this form:
function run() : Void {
//Put your code here
}
you'll have the ability to quickly modify and visualize whatever content appears
inside the body of the function by using the Design Preview capability within Net-
Beans. Listing 6.2 contains a sample
run()
function.
Figure 6.6 shows what is produced when the code in Listing 6.2 is compiled and
executed.
Figure 6.6
Demonstrating a Text Node with a DistantLight Lighting Effect
For our next two lighting examples, we'll use the same basic content, a
Text
node inside a black
Rectangle
; this time changing the text string and the light-
ing effect to see how the rendering of the image is affected. Figure 6.7 illustrates
an instance of
PointLight
being applied to text. The light source for
PointLight
has an (
x
,
y
,
z)
coordinate of (0, -500, 100).
As part of the demonstration, an additional instance variable that can be utilized
with
PointLight
, called
surfaceScale
, is assigned a value of 5. The range of
Search WWH ::
Custom Search