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

This will allow you to change gameButton to be helpButton, scoreButton, legalButton, and
creditButton, respectively, to create five unique UI Button objects. Your Java 9 game code for your Buttons
should look like this:


gameButton = new Button();
gameButton.setText("Start Game");
helpButton = new Button();
helpButton.setText("Game Rules");
scoreButton = new Button();
scoreButton.setText("High Scores");
legalButton = new Button();
legalButton.setText("Disclaimers");
creditButton = new Button();
creditButton.setText("Game Credits");


Adding the New UI Design Nodes in addNodesToSceneGraph()


As you can see in Figure 8-13, the Java code is error-free, and I have now declared and instantiated another
Group object named gameBoard. This will hold the 3D game elements branch of the SceneGraph, so the
Group object declaration has now become a compound statement at the top of your class. I clicked the
gameBoard object in the code to create a highlighted tracking of this object’s declaration, instantiation in
createBoardGameNodes(), and use in addNodesToSceneGraph(), showing that if you declare at the top of
the class, you can use objects anywhere you need to. This click object name to track is a useful NetBeans
9 trick and is one you will want to use whenever you want to track object usage. I will be using it often in
screenshots to highlight what I’m doing (and why) as I add new Java code.


Figure 8-12. Create 10 Button object instantiation and configuration statements at the end of
createBoardGameNodes()

Free download pdf