Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 8 ■ JavaFX 9 SCene Graph hierarChy: a Foundation For Java 9 Game deSiGn


Remember that if you declare any object by using its class name at the top of your class and a wavy red
underline appears underneath it, you can simply use the Alt+Enter keystroke combination and select the
import javafx.packagename.classname option to have NetBeans code the import statement for you.
As you can see in Figure 8-4, there is often more than one possible import statement in a pop-up helper
dialog, so be sure to select the classes from the JavaFX API since that is what we will be using for rich media,
IoT, and games development; that is where all of the multimedia production features are now kept in the
Java 9 APIs.
In the case of our new top-level Group SceneGraph Node subclass, there is also the java.security.acl.
Group class and a second javafx.swing.GroupLayout.Group helper class. Since we are not using Swing UI
elements (Java 5) and ACL security here, we know that the correct import statement for us to select is the
javafx.scene.Group option.


JavaFX Object Declarations: Global Class Access for Methods


Let’s add JavaFX object declarations and names for the new classes we’ve covered and the ImageView
and TextFlow objects we’ll be needing in the next chapter on designing the UI visuals and splash screen
elements for the game. Add a VBox object (button alignment) named uiContainer, an Insets object named
uiPadding, an ImageView object named boardGameBackPlate, a TextFlow object named infoOverlay,
and five Image objects named splashScreen, helpLayer, legalLayer, creditLayer, and scoreLayer. Add
four more Button objects to your Button declaration named helpButton, legalButton, creditButton,
and scoreButton, and change the bootstrap code–generated btn Button object to instead be named
gameButton. You can see the block of nine lines of declaration code, some of which will be compound
declarations with one class name and multiple object names (such as Image and Button below, and soon,
we’ll also have multiple Group objects named root and gameBoard), in the following Java 9 code, as well as
in Figure 8-6:


Scene scene;
Group root;
StackPane uiLayout;
VBox uiContainer;
Insets uiPadding;
ImageView boardGameBackPlate;
TextFlow infoOverlay;
Image splashScreen, helpLayer, legalLayer, creditLayer, scoreLayer; // Compound
Declaration
Button gameButton, helpButton, legalButton, creditButton, scoreButton; // a Compound
Declaration

Free download pdf