Java Reference
In-Depth Information
Listing 11.8
JavaFX Reflection - Function Invocation with Parameters
// call Point2D.distance(x:Number, y:Number): Number;
FXFunctionMember func = classRef.getFunction(
"distance",
context.getNumberType(),
context.getNumberType() );
FXValue val = func.invoke( obj,
context.mirrorOf(3.0),
context.mirrorOf(3.0));
System.out.println(val.getValueString());
Because the JavaFX Reflection API is written in Java, you can easily use the
same classes from within a JavaFX script. Just change the format to JavaFX.
Listing 11.9 shows an example of using the JavaFX Reflection API from JavaFX.
Listing 11.9
JavaFX Reflection - from JavaFX
def context:FXLocal.Context = FXLocal.getContext();
def classRef = context.findClass(
point.getClass().getName()));
var obj = context.mirrorOf(point);
var xVar = classRef.getVariable("x");
xVar.setValue(obj, context.mirrorOf(55.0));
Chapter Summary
It is easy to incorporate Java classes into JavaFX script. However, it helps to
understand some of the basic rules for doing this. This chapter has provided you
with the basics for interacting between the two environments. First, we discussed
the inclusion of Java object within JavaFX script, then we discussed the Java
Script API for JavaFX, and lastly we covered the JavaFX Reflection API.
Now you have the basics. In the next chapter, we cover JavaFX code recipes.
After that, we are going to bring it all together in a JavaFX Sudoku application.
Even the Sudoku application uses Java by incorporating an open source Java
library from SourceForge to generate and solve the Sudoku puzzle.
 
 
Search WWH ::




Custom Search