Java Reference
In-Depth Information
public class HeronsFormulaDirectExtensionExample {
public static void main(String[] args) {
final DoubleProperty a = new SimpleDoubleProperty(0);
final DoubleProperty b = new SimpleDoubleProperty(0);
final DoubleProperty c = new SimpleDoubleProperty(0);
DoubleBinding area = new DoubleBinding() {
{
super.bind(a, b, c);
}
@Override
protected double computeValue() {
double a0 = a.get();
double b0 = b.get();
double c0 = c.get();
if ((a0 + b0 > c0) && (b0 + c0 > a0) && (c0 + a0 > b0)) {
double s = (a0 + b0 + c0) / 2.0D;
return Math.sqrt(s * (s - a0) * (s - b0) * (s - c0));
} else {
return 0.0D;
}
}
};
a.set(3);
b.set(4);
c.set(5);
System.out.printf("Given sides a = %1.0f, b = %1.0f, and c = %1.0f," +
" the area of the triangle is %3.2f\n", a.get(), b.get(), c.get(),
area.get());
a.set(2);
b.set(2);
c.set(2);
System.out.printf("Given sides a = %1.0f, b = %1.0f, and c = %1.0f," +
" the area of the triangle is %3.2f\n", a.get(), b.get(), c.get(),
area.get());
}
}
The direct extension method is preferred for complicated expressions and for expressions that go beyond the
available operators.
Now that you have mastered all the APIs in the javafx.beans , javafx.beans.binding , javafx.beans.property ,
and javafx.beans.value packages, you are ready to step beyond the details of the JavaFX properties and bindings
framework and learn how these properties are organized into bigger components called JavaFX Beans.
Understanding the JavaFX Beans Convention
JavaFX introduces the concept of JavaFX Beans, a set of conventions that provide properties support for Java objects.
In this section, we talk about the naming conventions for specifying JavaFX Beans properties, several ways of
implementing JavaFX Beans properties, and finally the use of selection bindings.
 
Search WWH ::




Custom Search