Game Development Reference
In-Depth Information
JavaFX Scene Class: Scene Size and Color and Scene
Graph Nodes
The two primary classes in the javafx.scene package are the Scene class and the Node
class. I will be covering the Node class and its Parent , Group , and SubScene sub-
classes in the next section, as those classes, along with their subclasses (such as the
StackPane class used in the InvinciBagel class) are used to implement the Scene Graph
architecture in JavaFX. Also, in a sense (and in my diagram) the Node class and its
subclasses can be viewed as being below the Scene class, although the Node class is
not a subclass of the Scene class. In fact, the Node (Scene Graph) class and subclasses,
or rather the objects created using these classes, are contained inside the Scene object
itself.
For this reason, you will first consider how the Scene class, and its Scene() con-
structor method, is used to create Scene objects for JavaFX applications. This section
will provide reinforcement of what you learned in Chapter 3 regarding overloading
constructor methods, as there needs to be several different ways to create a Scene ob-
ject.
The Scene class is used to create a Scene object, using the Scene() constructor
class, which takes between one and five parameters, depending on which of the six
(overloaded) constructor methods you choose to use. These include the following con-
structor methods, along with their six different (and thus overloaded) parameter list
data field configurations:
Scene( Parent root)
Scene( Parent root, double width, double height)
Scene( Parent root, double width, double height, boolean
depthBuffer)
Scene( Parent root, double width, double height, boolean
depthBuffer, SceneAntialiasing aAlias)
Scene( Parent root, double width, double height, Paint
fill)
Scene( Parent root, Paint fill)
The constructor currently used in your bootstrap Java and JavaFX code is the
second one, called as follows:
Scene scene = new Scene(root, 300, 250);
Search WWH ::




Custom Search