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


Finally, you’ll take an in-depth look at the bootstrap JavaFX application code that you generated in
Chapter 6 and look at how the Java .main() method and the JavaFX .start() method create the primaryStage
Stage object using the Stage() constructor method and, inside of that, create a Scene object named scene
using the Scene() constructor method. You’ll look at how to use methods from the Stage class to set the
Scene, title the Stage, and show the Stage. You’ll learn how to create and use StackPane and Button class
objects and how to add an EventHandler to a Button.


Overview of JavaFX: From SceneGraph Down to OS


As I did in Chapter 2 and Chapter 3 covering new media, I want to start at the highest level with JavaFX,
which is the Scene Graph. This is the level right under the new media asset types that were shown on the
very top level in Figure 2-1 and Figure 3-7. JavaFX API’s Scene Graph Java code can also be built by using
the Gluon drag-and-drop JavaFX Scene Builder, which can be integrated into NetBeans 9, as you learned in
Chapter 6 , or used as a stand-alone. We will be looking at how to “scratch-code” all of these scene structures
since this is Pro Java 9 Games Development.
As you can see in Figure 7-1, the JavaFX Scene Graph Architecture sits on top of the JavaFX API, a
collection of JavaFX packages such as javafx.scene or javafx.application, which is what ultimately allows
you to build your Scene Graph and design your JavaFX new media creations. In this case, it will be a pro Java
game. Notice that the JavaFX API is connected (using steel bearings on this diagram to denote bridges) not
only to the Scene Graph Architecture above it but also to the Java API and its JavaFX Quantum toolkit below
it. As you can see, the Java JDK (and API) connects the JavaFX new media engine to NetBeans 9 and to the
JVM. The JVM allows Java to distribute your Pro Java Game across the various platforms that Java currently
supports, as well as future (native support) platforms like Android 8 and iOS.


Figure 7-1. JavaFX Component Architecture from Scene Graph at the top down through Java, NetBeans, JVM,
and OSs

Free download pdf