Java Reference
In-Depth Information
Image
There is a special
url
syntax for defining images.
background-image: url(http://jfxbook.com/NASA/nasa.jpg);
This actually creates a
java.awt.image.BufferedImage
object that can then be
used to create a
javafx.scene.Image
. A JavaFX example to handle this is
shown in Listing 5.12.
Listing 5.12
JavaFX Example for Creating Image from BufferedImage
var image: Image;
public var backgroundImage:
java.awt.image.BufferedImage
on replace {
if(backgroundImage != null) {
image =
Image{}.
fromBufferedImage(backgroundImage);
}
}
As we already mentioned, a scene graph is a representation of a display scene. It is
represented as a tree data structure with a set of linked nodes. Nodes may be either
inner nodes, sometimes called branch nodes or leaf nodes that have no children.
The
javafx.scene.Node
class is the base class for all the
scene
graph nodes.
In JavaFX, the
Scene
is the root node and contains a set of direct child nodes;
inner nodes are either a
javafx.scene.Group
or
javafx.scene.CustomNode
.
The leaf nodes are all the other nodes like shapes, controls, text, and the Swing
Extension nodes.
Each node may be given an ID represented as a string. A lookup function is pro-
vided to find a node with a specific ID. Already, we saw ID used in conjunction
with style sheets and the developer should take care to assign unique IDs when
they are used.
Nodes have a set of instance variables of function type that can be assigned and
are called when certain input events occur. These include the
onKey
XXXX
and
onMouse
XXXX
instance variables that hold functions to handle key or mouse events,
where
XXXX
represents the specific type of event. The
blocksMouse
instance
variable indicates whether mouse events should be delivered to the parent. These
will be discussed in more depth in the section Input Events, later in this chapter.
Search WWH ::
Custom Search