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

JavaFX Business Charting: Using the javafx.scene.chart Classes


The javafx.scene.chart package is in the javafx.controls module with the predefined UI controls (UI elements).
This package contains the business charting classes, such as Chart, ScatterChart, StackedAreaChart, XYChart,
PieChart, LineChart, BarChart, StackedBarChart, AreaChart, BubbleChart and the like, for use in business
applications, which is a different book entirely, so we won’t be covering charting during this book. In fact,
for my games I’m going to use a 3D UI approach, which would mean that I don’t need to include the javafx.
controls module (a massive amount of classes) at all, meaning my game module would only have to include
javafx.base, javafx.media and javafx.graphics, making the distribution a significantly smaller download (base
has only 10 packages, media has 9, while graphics has 18 as you have seen throughout this chapter).


JavaFX Media Control: Using the javafx.scene.media Classes


The javafx.scene.media package is contained in the javafx.media module and contains classes that are
used for the playback of audio and video media assets, including the Media, MediaPlayer, and MediaView
classes, as well as the AudioClip, AudioEqualizer, EqualizerBand, Track, VideoTrack, and SubtitleTrack
classes. The Media class (or object) references or contains an audio or video media asset, the MediaPlayer
plays that asset, and the MediaView, especially in the case of video, displays the digital audio or video media
asset along with a transport used for media playback.
We will be using the AudioClip class later in this book when we add digital audio sound effects for your
pro Java 9 game, and as long as we are using the digital audio portions of this module, if we have to include
it in your application (modules) distribution, we might as well leverage the digital video asset (video classes)
features as well.


JavaFX Web Rendering: Using the javafx.scene.web Classes


The javafx.scene.web package is contained in the javafx.web module and contains classes for rendering web
(Internet) assets in a scene. This package contains a collection of classes, including WebEngine, WebView,
WebEvent, WebHistory, and HTMLEditor. The WebEngine class (hey, someone else calls these algorithms
engines), as you might imagine, does the processing for showing HTML5, CSS3, CSS4, and JavaScript in
JavaFX Scenes, and the WebView creates the Node to display the WebEngine output in a JavaFX Scene
Graph. The WebHistory class (object, ultimately) holds the Internet “session,” from WebEngine instantiation
to removal from memory, which is a history of web pages visited, and the WebEvent class “bridges” the
JavaScript web event processing with the JavaFX 9 event processing. We will not be using the javafx.web
module for the i3D game that we will be creating over the course of this book, as I am going to focus on the
core APIs that can be used to provide the most visually professional i3D gameplay results.


Other JavaFX Packages: Print, FXML, Beans, and Swing


There are a few other JavaFX packages that you should take a closer look at before you are done with this
JavaFX overview chapter, as they are packages that contain classes that you may want to use in your pro Java
games development but that provide more specialized capabilities such as printing, using third-party Java
code, using older UI paradigms such as AWT and Swing, and offloading UI design to nonprogrammers using
XML (specifically FXML). These APIs include the javafx.print package (javafx.graphics module), javafx.fxml
package (javafx.fxml module), javafx.beans package (javafx.base module), and javafx.embed.swing package
(javafx.swing module). You are not likely to use these in your Java game design and development work
process unless you have a specialized need for your project. The most obvious of these is javafx.print used
to allow printers to work with your pro Java 9 games. If you need to use older Swing UI elements, there is a
javafx.swing module that will allow this but will add a bigger data footprint to your Java 9 game distribution.
The javafx.beans package will allow you to use Java Beans (third party or added-in classes), and the javafx.

Free download pdf