Java Reference
In-Depth Information
The last scenario on binding numbers is considered more of a low-level approach.
This allows developers to use primitives and more complex math operations. Here, you
use a DoubleBinding class to solve the volume of a sphere given the radius. You
begin by implementing the computeValue() method to perform the calculation of
the volume. Shown is the low-level binding scenario to compute the volume of a
sphere by overriding the computeValue() method:
final DoubleProperty radius = new SimpleDoubleProperty(2);
DoubleBinding volumeOfSphere = new DoubleBinding() {
{
super.bind(radius);
}
@Override
protected double computeValue() {
return (4 / 3 * Math.PI
* Math.pow(radius.get(), 3));
}
};
14-10. Creating and Working with Ob-
servable Lists
Problem
You want to create a GUI application containing two list view controls that allow users
to pass items between the two lists.
Solution
You can take advantage of JavaFX's javafx.collections.ObservableList
and javafx.scene.control.ListView classes to provide a model-view-con-
troller (MVC) mechanism that updates the UI's list view control whenever the backend
list is manipulated.
Search WWH ::




Custom Search