Java Reference
In-Depth Information
start( ) has a parameter of type Stage . When start( ) is called, this parameter will receive a
reference to the primary stage of the application. It is to this stage that you will set a scene
for the application.
After displaying a message on the console that start( ) has begun execution, it sets the
title of the stage using this call to setTitle( ) :
Although this step is not necessarily required, it is customary for stand-alone applications.
This title becomes the name of the main application window.
Next, a root node for a scene is created. The root node is the only node in a scene graph
that does not have a parent. In this case, a FlowPane is used for the root node, but there are
several other classes that can be used for the root.
As mentioned, a FlowPane uses a flow layout. This is a layout in which elements are posi-
tioned line-by-line, with lines wrapping as needed. (Thus, it works much like the FlowLay-
out class used by the AWT and Swing.) In this case, a horizontal flow is used, but it is pos-
sible to specify a vertical flow. Although not needed by this skeletal application, it is also
possible to specify other layout properties, such as a vertical and horizontal gap between
elements, and an alignment.
The following line uses the root node to construct a Scene :
Scene provides several versions of its constructor. The one used here creates a scene that
has the specified root with the specified width and height. It is shown here:
Scene(Parent rootnode , double width , double height )
Notice that the type of rootnode is Parent . It is a subclass of Node and encapsulates nodes
that can have children. Also notice that the width and the height are double values. This
lets you pass fractional values, if needed. In the skeleton, the root is rootNode , the width is
300, and the height is 200.
The next line in the program sets myScene as the scene for myStage :
Search WWH ::




Custom Search