Java Reference
In-Depth Information
Once the applet has been initialized, we can ask for an instance of the applet
object using the JavaScript function document.getElementById("js2jfx") .
F The JavaScript update() function —the other function in the <script/> block is the
update() function. This is where the JavaScript code interacts with the applet, so
let's take a look:
var js2jfx = document.getElementById("js2jfx") —this
line obtains a reference to the JavaFX applet (see previous bullet).
This object is used to communicate with the JavaFX applet directly.
Accessing JavaFX public properties—Now that we have a reference
to the JavaScript applet object, we can use js2jfx.script to
update or access the value of any JavaFX script-level property.
For instance, js2jfx.script.textContent = document.
getElementById("msg").value assigns the value of JavaScript
object msg to the JavaFX script-level property textContent .
Calling JavaFX functions—similar to accessing JavaFX properties,
js2jfx.script can also be used to invoke JavaFX public
script-level functions. In our example, the JavaScript call js2jfx.
script.applyEffect(...) invokes the JavaFX public script-level
function applyAffect(number) declared in the JavaFX code.
F The HTML form —the remainder of the HTML source code contains the HTML
form used to control the applet. When the Set button is clicked, it invokes the
update() JavaScript function defined in the <script> block, which in turn
passes all the collected values to the JavaFX code through the JavaScript applet
object (see previous bullet).
As of version 6, update 18 of the Java's consumer runtime (JRE)
when this was tested, the features presented here only worked with
the next generation Java Plugin running on the Windows platform.
By the time you read this, support may be available for browsers on
other platforms.
There's more...
As discussed above, the JavaFX-JavaScript bridge lets you access JavaFX script-level public
variables and functions. This mechanism offers much more than depicted in the recipe above;
let's explore some additional capabilities.
Type crossing JavaScript to JavaFX
When updating JavaFX script-level properties or invoking a parameterized function, the
Java browser plugin framework will conduct an automatic type conversion to handle data
representation from JavaScript to the JavaFX environment. Here is is chart showing how
JavaFX types are mapped to JavaScript values.
Search WWH ::

Custom Search