Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 5 ■ a Java primer: introduCtion to Java ConCepts and prinCiples


For example, javafx.web (the WebKit API WebEngine) will require javafx.controls (used for the UI
elements for the audio and video transport bar user interface element), javafx.media (audio or video
playback codec support), and javafx.graphics (application, stage, scene, geometry, image, shapes, canvas,
effects, text, and animation support).
Since modular applications need to list dependencies in that module-info.java file, let’s take a
look at how that would look for an application that uses the WebKit support API in JavaFX. Here’s the
module-info.java syntax:


module myWebKitApp.app { requires javafx.web; }


You might be wondering why you do not explicitly have to require those other modules that the
javafx.web module requires in the module-info.java file’s module myWebKitApp.app { ... } module use
declaration, which one might suspect should look more like this:


module myWebKitApp.app {
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;
requires javafx.media;
requires javafx.web;
}


This is because modules required by modules further down the chain are imported (required)
automatically as part of the syntax. So, if we created a JavaFX game that did not use “canned” UI elements
(called controls in JavaFX) or WebKit, FXML, or Java Swing, we could get away with using just base, graphics,
and media modules.
Since the javafx.graphics module requires javafx.base and the javafx.media module requires javafx.
graphics, you can simply write the entire module declaration Java file in one line of code, which would look
like the following:


module ProJava9GamesDevelopment.app { requires javafx.media; }


Table 5-6. Seven Core JavaFX Modules Contained in the Java 9 Runtime Environment for Use in New Media
Applications


Module Name Required? Used For Required JavaFX 8 Modules


javafx.base Ye s Events, Utilities, Beans, Collections None (this is a Foundational
JavaFX Library)


javafx.graphics Ye s Stage, Images, Geometry, Animation javafx.base


javafx.controls No User Interface Controls Module javafx.graphics (require will
also import base)


javafx.media Ye s Audio/Video MediaPlayer Module javafx.graphics


javafx.fxml No JavaFX Markup Language Module javafx.graphics


javafx.swing No Java Swing Compatibility Module javafx.graphics


javafx.web No WebKit Support Module javafx.controls, javafx.
media, javafx.graphics

Free download pdf