Game Development Reference
In-Depth Information
JavaFX Screen and Window Control: Using
javafx.stage Classes
The javafx.stage package contains classes that can be considered top level, in terms of
the display for your JavaFX application (in this case, a game). This display is at the top
of the resulting game play, because it shows your game's scenes to the end user of your
application. Inside the Stage object are Scene objects, and inside these are Scene Graph
Node objects, which contain the elements that make up an application.
In contrast, the classes that are in this package could be considered fairly low level ,
from an OS perspective; these are the Stage , Screen , Window , WindowEvent ,
PopupWindow , Popup , DirectoryChooser , and FileChooser classes as well as the
FileChooser.ExtensionFilter nested class. These classes can be used to interface with
the device's display hardware, and the OS software's windowing management, file
management, and directory (folder) management functionality.
To get a description of the display hardware that is being used by the device that a
JavaFX application is running on, you will want to use the Screen class. This class
supports multiscreen (commonly referred to as second screen ) scenarios, using the
.getScreens() method, which can access an ObservableList object that will contain a
list (array) with all the currently available screens. A primary screen is accessed using
the .getPrimary() method call. You can get the physical resolution for the primary
screen hardware by using a .getDpi() method call. There are also .getBounds() and
.getVisualBounds() method calls for usable resolution.
The Window superclass, and its Stage and PopupWindow subclasses, can be used
by the JavaFX end user to interact with your application. As you saw in Chapter 3 (see
Figure 3-2 ) , this is done using the Stage object named primaryStage, which is passed
into your .start() method, or using a PopupWindow (dialog, tool tip, context menu, no-
tification, and so on) subclass, such as a Popup or PopupControl object.
You can use the Stage class to create secondary stages within your JavaFX applica-
tion programming logic. A primary Stage object is always constructed by the JavaFX
platform, using the public void start(Stage primaryStage) method call, as you have
already seen in Chapters 2 and 3 in the bootstrap JavaFX application created by
NetBeans.
All JavaFX Stage objects must be constructed using, and modified inside the
primary JavaFX application thread, which I discussed in the previous section. Because
a stage equates to a window on the OS platform it is running on, certain attributes or
properties are read-only , as they need to be controlled at the OS level; these are
Boolean properties (variables): alwaysOnTop , fullScreen , iconified , and maximized .
Search WWH ::




Custom Search