Java Reference
In-Depth Information
Create nodes in the scene. These nodes are subclasses of the javafx.scene.Node class,
which include UI controls, shapes, Text (a type of shape), images, media players,
embedded browsers, and custom UI components that you create. Nodes can also be
containers for other nodes, often providing cross-platform layout capabilities. A scene
has a scene graph that contains a directed graph of nodes. Individual nodes and groups
of nodes can be manipulated in many ways (e.g., moving, scaling, and setting opacity) by
changing the values of a very rich set of Node properties.
3.
4.
Create variables and classes that represent the model for the nodes in the scene. As discussed
in Chapter 1, one of the very powerful aspects of JavaFX is binding, which enables the
application's UI to stay in sync easily with the state, or model, of the application.
Most of the examples in this chapter are small programs intended to demonstrate Ui concepts. for this reason,
the model in many of these examples consists of variables appearing in the main program, rather than being contained
by separate Java classes (e.g., the AudioConfigModel class in Chapter 1).
Note
Create event handlers, such as onMousePressed , that allow the user to interact with your
program. Often these event handlers manipulate instance variables in the model. Many of
these handlers require a single abstract method to be implemented, and as a consequence
provide a perfect opportunity to use lambda expressions.
5.
6.
Create timelines and transitions that animate your scene. For example, you might want the
thumbnail images of a list of topics to move smoothly across the scene or a page in the
UI to fade into view. You might simply want a ping pong ball to move across the scene,
bouncing off walls and paddles, which is demonstrated later in this chapter in the section,
“The Zen of Node Collision Detection.”
Let's get started with a closer look at Step 1, in which we examine the capabilities of the stage.
Setting the Stage
The appearance and functionality of your stage will depend on the platform on which it is deployed. For example,
if deployed in an embedded device with a touch screen, your stage might be the whole touch screen. The stage for a
JavaFX program deployed via Java Web Start will be a window.
Understanding the Stage Class
The Stage class is the top-level container for any JavaFX program that has a graphical UI. It has several properties
and methods that allow it, for example, to be positioned, sized, given a title, made invisible, or given some degree
of opacity. The two best ways that we know of to learn the capabilities of a class are to study the JavaFX API
documentation and to examine (and write) programs that use it. In this section, we ask you to do both, beginning with
looking at the API docs.
The JavaFX API docs may be found in the docs/api directory subordinate to where you installed the
JavaFX SDK. Also, they are available online at the URL given in the Resources section at the end of this chapter.
Open the index.html file in your browser, navigate to the javafx.stage package, and select the Stage class. That
page should contain tables of Properties, Constructors, and Methods, including select ones shown in the excerpt in
Figure 2-1 .
 
 
Search WWH ::




Custom Search