Java Reference
In-Depth Information
By invoking the jjs tool in this manner, the scripting options are automatically
enabled, allowing you to utilize scripting features within the script. The following list
includes extra scripting features that can be used when executing via jjs with script-
ing options are enabled:
String interpolation: (See Recipe 18-3)
var threeyr = 365 * 3;
print("The number of days in three years is
${threeyr}");
Shell invocations: The ability to invoke external programs
Special environment variables are available for use ( $ARG and $ENV )
The ability to develop executable scripts in JavaScript can be very powerful. Not
only is the world of JavaScript available at your fingertips, but the entire Java world is
available, since you can import Java classes and libraries into your scripts.
18-11.
Implementing
JavaFX
with
Nashorn
Problem
You enjoy working in JavaScript code and want to implement a Java GUI using
JavaScript.
Solution 1
Develop a JavaFX application using JavaScript and store it in a JavaScript file. Invoke
the file using the jjs tool, along with the -fx option. The following code is a JavaFX
application that is written in JavaScript. The JavaFX application can be used for col-
lecting car data.
var ArrayList = Java.type("java.util.ArrayList");
var Scene = javafx.scene.Scene;
Search WWH ::




Custom Search