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

I did this to make sure each button is implementing its own event handling and is printing out the
correct System.out.println() text message when I click each of the five UI Button Controls.
Later we can replace this System.out.println() method call with a different one that controls the
ImageView reference to the Image object, allowing us to switch between your digital image assets for your
user interface design ImageView digital image backplate holder.
Since we only copied and pasted the EventHandler routines for each Button and changed only your
Button objects names and the code that is executed inside of these routines, these Button objects should
still work properly (writing text to the console) and not cause any compiler errors. However, they will not
ultimately do what you want them to, which is to change the Image object, which is referenced in the
ImageView object (UI backplate) underlay, or to place the proper text over this using the TextFlow. This is
what you are going to be coding in the next chapter; you’ll also do some UI design tweaking that will put the
Button bank in the proper location on the display screen. As you can see in Figure 8-16, although the Button
Control objects are indeed aligned at the TOP_RIGHT position inside the VBox UI container Node, the VBox
itself is not yet aligned within its Parent (branch) StackPane Node object. Just like with the transparency in
Chapter 7 , the VBox (in StackPane) and StackPane (in a Group) must be positioned correctly.
Congratulations, you have maintained the improvements added in Chapter 7 and put in place new
methods for organizing your Scene Graph hierarchy and improved this Scene Graph to include your i3D
game branch, which we will start to add objects and assets into during the second half of the book.


Figure 8-17. Click each of the Button objects and make sure your event-handling code is printing the right
messages

Free download pdf