Java Reference
In-Depth Information
The individual elements of a scene are called
nodes
. For example, a push button control is
a node. However, nodes can also consist of groups of nodes. Furthermore, a node can have
a child node. In this case, a node with a child is called a
parent node
or
branch node
. Nodes
without children are terminal nodes and are called
leaves
. The collection of all nodes in a
scene creates what is referred to as a
scene graph
, which comprises a
tree
.
There is one special type of node in the scene graph, called the
root node
. This is the top-
level node and is the only node in the scene graph that does not have a parent. Thus, with
the exception of the root node, all other nodes have parents, and all nodes either directly or
indirectly descend from the root node.
The base class for all nodes is
Node
. There are several other classes that are, either direc-
tly or indirectly, subclasses of
Node
. These include
Parent
,
Group
,
Region
, and
Control
,
to name a few.
Layouts
JavaFX provides several layout panes that manage the process of placing elements in a
scene. For example, the
FlowPane
class provides a flow layout and the
GridPane
class
supports a row/column grid-based layout. Several other layouts, such as
BorderPane
(which is similar to the AWT's
BorderLayout
), are available. Each inherits
Node
. The lay-
outs are packaged in
javafx.scene.layout
.
The Application Class and the Life-cycle Methods
A JavaFX application must be a subclass of the
Application
class, which is packaged in
javafx.application
. Thus, your application class will extend
Application
. The
Applica-
tion
class defines three life-cycle methods that your application can override. These are
called
init( )
,
start( )
, and
stop( )
, and are shown here, in the order in which they are called:
void init( )
abstract void start(Stage
primaryStage
)
void stop( )
The
init( )
method is called when the application begins execution. It is used to perform
various initializations. As will be explained, it
cannot
, however, be used to create a stage or
build a scene. If no initializations are required, this method need not be overridden because
an empty, default version is provided.
The
start( )
method is called after
init( )
. This is where your application begins and it
can
be used to construct and set the scene. Notice that it is passed a reference to a
Stage