Java Reference
In-Depth Information
Object fxObj = FXEvaluator.eval(
"println('hello world'); 'hello world';");
System.out.println("JavaFX Object = " + fxObj);
if(fxObj != null) {
System.out.println("JavaFX Class = " +
fxObj.getClass());
}
This now produces
hello world
JavaFX Object = hello world
JavaFX Class = class java.lang.String
Now let's do something a bit more complicated, as depicted in Listing 11.1.
Listing 11.1
Java Scripting for JavaFX
import javafx.util.FXEvaluator;
public class Complex {
public static void main(String[] args) {
String script =
"public class Student {" +
" public var name:String;" +
" public var age:Integer;" +
"}" +
" function run(args: String[]):Void { " +
"
Student { name: 'Jim' age: 29 };" +
"}";
Object fxObj = FXEvaluator.eval(script);
System.out.println("JavaFX Object = " + fxObj);
if(fxObj != null) {
System.out.println("JavaFX Class = " +
fxObj.getClass());
}
}
}
This produces a returned object for Student :
JavaFX Object = ___FX_SCRIPT___$Student@c8769b
JavaFX Class = class ___FX_SCRIPT___$Student
FXEvaluator is a way to simply execute a JavaFX script and get a resulting
object back. However, instead of hard coding “jim”, age 29, in the script, what if
 
Search WWH ::




Custom Search