Java Reference
In-Depth Information
accessing JavaFX from Java. This is more important to people doing intense
development with Java and JavaFX and by its nature requires a more in-depth
knowledge of Java. If you are not interested in accessing JavaFX from Java, you
may skip these last two sections.
Classes
As we mentioned in Chapter 3, JavaFX Primer, JavaFX classes can extend multi-
ple Java interfaces, but can only extend at most one Java class, and that Java class
must have a default (no args) constructor.
public class MyJavaFXClass extends java.awt.Point {
When extending a Java class, all the accessible methods and attributes of that
class are available to the JavaFX class. However, none of the Java class attributes
or functions may participate in JavaFX binding. Remember from Chapter 3 that
JavaFX Script is a declarative language with object orientation and is a forgiving
environment. Even if you try to bind to a Java object's attribute, the runtime sys-
tem will silently ignore the updates. To illustrate this
class FooBar1 extends java.awt.Point {
public var fxPointX = bind x;
}
var f = FooBar1{};
println("f.x = {f.x} f.fxPointX = {f.fxPointX}");
f.x = 100;
println("f.x = {f.x} f.fxPointX = {f.fxPointX}");
When this is run, f.x is updated, but f.fxPointX is not updated, and there is no
error or warning message.
f.x = 0 f.fxPointX = 0
f.x = 100 f.fxPointX = 0
The main message here is you can extend Java classes, but the attributes and
methods from those classes have no inherent connection to some of the advanced
binding and trigger features found in JavaFX. For more detailed information on
binding and triggers, check out Chapter 4, Synchronize Data Models—Binding
and Triggers.
 
Search WWH ::




Custom Search