Java Reference
In-Depth Information
Figure 4.1
The Two Individual Display States for This Application Depend upon
Where the Mouse Is Located
or exits the image on the display. When the mouse pointer enters the image,
the
onMouseEntered
handler will be executed setting the
currentImage
variable to
image1
. When the mouse leaves the image, the
onMouseExited
handler will execute setting
currentImage
to
image2
.
3. The actual display is updated by binding the value of
currentImage
to
ImageView
's
image
instance variable. In particular, the line of code repre-
sented by
image: bind currentImage
makes this happen.
When binding to arithmetic and logical expressions, a bind recalculation takes
place if any component of the expression appearing to the right of the
bind
key-
word changes. Let's run through an example to demonstrate:
var a = 3;
var b = 4;
var c = a * b;
var d = 7;
var total = bind c + d;
println("total={total}");
d = 10;
println("total={total}");
b = 5;
println("total={total}");
prints out:
total=19
total=22
total=22
The definition of the variable
total
specifies that its value will be recalculated
whenever
c
or
d
change. The second line of output (
total=22
) is the result of a
Search WWH ::
Custom Search