Java Reference
In-Depth Information
FXLocal.ObjectValue obj =
(ObjectValue)classRef.newInstance();
Or, if you need to initialize some of the objects instance variables:
FXLocal.ObjectValue obj =
(ObjectValue) classRef.allocate();
obj.initVar("x", context.mirrorOf(-1.0));
obj.initVar("y", context.mirrorOf(-1.0));
obj.initialize();
After the object instance is created, you can get instance variables via the
FXClassType getVariable()
methods and access the class functions via the
get-
Function()
methods. To set the
x
and
y
instance variables in
javafx.geometry
.Point2D
, you must first get the
FXVarMember
for the
x
and
y
instance variables,
and then set their respective values:
FXVarMember xVar =
classRef.getVariable("x");
FXVarMember yVar = classRef.getVariable("y");
xVar.setValue(obj, context.mirrorOf(25.0));
yVar.setValue(obj, context.mirrorOf(50.0));
The
context.mirrorOf()
function wrappers the value with a proxy that uses
the local VM to handle the reflection.
If you have a Java method parameter that is a JavaFX object, you convert that to
a
FXLocal.ObjectValue
using context.
mirrorOf
as shown in Listing 11.6.
Listing 11.6
JavaFX Reflection
public static void manipulate(
javafx.geometry.Point2D point
) {
FXLocal.Context context = FXLocal.getContext();
FXClassType classRef =
context.findClass(
point.getClass().getName()
);
FXObjectValue obj =
context.mirrorOf(point);
FXVarMember xVar = classRef.getVariable("x");
FXVarMember yVar = classRef.getVariable("y");
xVar.setValue(obj, context.mirrorOf(55.0));
yVar.setValue(obj, context.mirrorOf(777.0));
To invoke functions, get the
FXFunctionMember
object for the function, then
invoke it using the instance
obj
as shown in Listing 11.7.
Search WWH ::
Custom Search