Java Reference
In-Depth Information
However, with diagnostic handling, we get the far more informative message:
ERROR: Line:5 Col:13
'cannot find symbol
symbol : variable nameBogus
location: class ___FX_SCRIPT___.Student'
Java Scripting for JavaFX provides a powerful tool for running JavaFX Script
from Java code. It allows you to evaluate scripts and get returned objects so that
later you can invoke functions on them. It is limited in that you cannot directly
manipulate instance variables. However, if used in conjunction with the JavaFX
Reflection API, even this limitation can be overcome.
JavaFX Reflection
The JavaFX Reflection package, javafx.reflect , allows complete access to
JavaFX objects from both Java and JavaFX code. The classes in javafx.reflect
are actually Java classes and can safely be used from Java programs. Nonethe-
less, you need to have the appropriate JavaFX SDK libraries in your classpath.
The first task to use the JavaFX Reflection is to find an object's class. You do
this by getting the javafx.reflect.FXContext, then using that to find the class
reference. We are using javafx.reflect.FXLocal.Context that implements
FXContext, because this class allows us to additionally mirror JavaFX objects,
whereas FXContext only allows mirroring of the JavaFX basic types. Mirroring
provides a proxy (a level of indirection) so that the same API could potentially
work with remote objects in a separate JVM. However, for now, the only imple-
mentation is on a local VM, hence the FXLocal implementation.
FXContext and the other javafx.reflect.FX xxxxx classes, like j avafx.reflect
.FXClassType and javafx.reflect.FXValue , are abstract APIs, whereas
FXLocal.Context and other FXLocal.X xxxxx classes, like javafx.reflect
.FXLocal.ClassType and javafx.reflect.FXLocal.Value , are concrete imple-
mentations of the JavaFX Reflection API. These FXLocal classes sit on top of Java
reflection, and thus require the mirrored values and types to be in the same VM.
FXLocal.Context context = FXLocal.getContext();
FXClassType classRef =
context.findClass ("javafx.geometry. Point2D");
After you obtain the classRef , you can either create an instance of the class or
use an existing object of that type to manipulate the object's state. To create a
new instance, call newInstance() on the classRef .
 
Search WWH ::




Custom Search