//rich client /
Lazy Evaluation, Lazy Initiation, and
Custom Bindings in JavaFX 2
JAMES L. WEAVER
Optimize the evaluation of bindings and the initialization of properties the lazy way.
JAVA IN ACTION
JavaFX 2 is an API and run- time for creating rich internet
applications (RIAs). It was introduced in 2007, and version 2 was
released in October 2011. One of
the advantages of JavaFX 2 is that
the code can be written in the
Java language, using mature and
familiar tools.
This article is Part 2 of a two-part series and focuses on optimizing JavaFX 2 properties and
binding by implementing lazy
evaluation, lazy initialization, and
custom bindings.
As discussed in the previous
article, “Using Properties and
Binding in JavaFX 2.0: Part 1,”
JavaFX 2 comes with a set of interfaces, which are shown in Figure 1.
The purpose of these interfaces is
to provide support for using and
implementing properties, detecting when the values of properties
have changed, and binding properties to other properties.
These interfaces are located in
four packages:
■ ■
javafx.beans
■ ■
javafx.beans.binding
■ ■
javafx.beans.property
■ ■
javafx.beans.value
This article contains an example
of using the methods defined by
many of these interfaces to imple-
ment lazy evaluation, lazy initial-
ization, and custom bindings.
of this article, you’ll modify the
code to implement the lazy
evaluation, lazy initialization,
and custom binding behavior of
the LazyInitEvalSolution project,
which is also available in the file
you’ll download.
As shown in Figure 3, when
you click the Start button on one
of the stopwatches, its elapsed
timer starts counting by milliseconds. In order to see the elapsed
time, however, you must click the
invalidate – click to bind/unbind
PHOTOGRAPH BY
STEVE GRUBMAN
Overview of the
LazyInitEvalSolution
Application
To help you learn how to use
properties and binding, an
example application named
LazyInitEvalSolution will be
employed. As shown in Figure 2,
this application contains three
stopwatches, and each has
some buttons and elapsed and
lap time displays.
The LazyInitEvalExercise
project that you’ll download
in the next section contains
starter code for the example
application. In its current
form, the application’s runtime appearance is similar to
Figure 2. During the course
ABOUT US
blog