Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 7 ■ IntroduCtIon to JavaFX 9: overvIew oF the JavaFX new MedIa engIne

The javafx.scene.layout.StackPane class is subclassed from the javafx.scene.layout.Region class,
which has a .setBackground() method to set the Background (class or object) value. Again, there must be
a TRANSPARENT value constant available, or something similar to that such as Background.EMPTY, as you
need to always set the background values to be transparent, especially for pro Java 9 game design, where you
need the flexibility to achieve advanced 2D and 3D compositing and rendering pipelines. This support for
transparency also holds true for Android UI containers.
It is interesting to note that things are not always as straightforward and consistent as we would want
them to be in Java programming, as we’ve used three different method calls, passing three custom object
types, thus far, to achieve exactly the same end result (installing a transparent background color/image plate
for the design element): .initStyle(StageStyle object), .setFill(Color object), and .setBackground(Background
object). This time, you are going to call a .setBackground(Background value) method with yet another
Background class (object) constant called EMPTY.
NetBeans 9 will help you to find the constant once you call the method off of the StackPane
object named root, using the root.setBackground(Background.EMPTY); Java statement. This time it
is easier as the Background.EMPTY constant happens to be the default configuration setting for the
.setBackground() method call. If you want to see all of the Background helper class constants, type root.
setBackground(Background. into NetBeans 9 and look at the results that appear in the constants pop-up
helper selector pane.
As you can see in Figure 7-10, NetBeans 9 provides a method selector drop-down, and once you select
and double-click the .setBackground(Background value) method, NetBeans 9 will write the code statement
for you, automatically inserting the default EMPTY constant called off of the Background class using


Figure 7-9. Set the Scene object fill color to TRANSPARENT, and notice that NetBeans codes a Color class
import statement

Free download pdf