Java Reference
In-Depth Information
System.out.println("area.get() = " + area.get());
System.out.println("area.get() = " + area.get());
System.out.println("Setting x to 5");
x.set(5);
System.out.println("Setting y to 7");
y.set(7);
System.out.println("area.get() = " + area.get());
}
}
In the anonymous inner class, we called the protected bind() method in the superclass DoubleBinding ,
informing the superclass that we would like to listen to invalidation events from the DoubleProperty objects x and y .
We finally implemented the protected abstract computeValue() method in the superclass DoubleBinding to do the
actual calculation when a recalculation is needed.
When we run the program in Listing 4-3, the following output is printed to the console:
Constructing x with initial value of 2.0.
Constructing y with initial value of 3.0.
Creating binding area with dependencies x and y.
computeValue() is called.
area.get() = 6.0
area.get() = 6.0
Setting x to 5
Setting y to 7
computeValue() is called.
area.get() = 35.0
Notice that computeValue() is called only once when we call area.get() twice in a row.
the DoubleBinding abstract class contains a default implementation of dispose() that is empty and a
default implementation of getDependencies() that returns an empty list. to make this example a correct Binding
implementation, we should override these two methods to behave correctly.
Caution
Now that you have a firm grasp of the key interfaces and concepts of the JavaFX properties and bindings
framework, we show you how these generic interfaces are specialized to type-specific interfaces and implemented in
type-specific abstract and concrete classes.
Type-Specific Specializations of Key Interfaces
We did not emphasize this fact in the last section because we believe its omission does not hurt the explanations
there, but except for Observable and InvalidationListener , the rest of the interfaces are generic interfaces with
a type parameter <T> . In this section we examine how these generic interfaces are specialized to the specific types
of interest: Boolean , Integer , Long , Float , Double , String , and Object . We also examine some of the abstract and
concrete classes of the framework and explore typical usage scenarios of each class.
 
 
Search WWH ::




Custom Search