Java Reference
In-Depth Information
How it works...
In the code presented in this recipe, we are using the JavaFX-JavaScript bridge mechanism,
provided by the new Java Plugin, to create programmatic interactions between a JavaFX applet
and the JavaScript code embedded within a web page. The JavaScript code on the web page
can do the following:
F Access JavaFX resources by calling functions
F Access and update variable values
F Pass in complex types
F Traverse JavaFX's scene graph
Let us examine how the JavaFX script is set up in order to accept programmatic interaction
with the JavaScript
F The JavaFX script —the JavaFX-JavaScript bridge accesses the JavaFX applet
through public script-level variables and functions declared in the main application
class. Therefore, our code declares several script-level members that can be reached
by JavaScript:
JavaFX public variable textContent is bound to the content
property of the Text object. When a value is assigned to it, it will
update the content of the Text node.
Public variables textColor:String , textColorEnd:String ,
textStrokeColor:String , textStrokeWidth:String , and
textFont:String are bound to the style property of the Text
object. This will allow the appearance of the Text node to be updated
when any of these variables are updated from the JavaScript code.
For instance, when the textColor = "red" , this will cause the
Text instance color to be updated to red.
The public function applyEffect(number):Void applies an
effect to the Text instance. The function can apply three effects to
the text including reflection, drop shadow, and lighting. Each effect
is associated with a number, where 0 = no effect. This makes easy
for the function to be invoked from JavaScript to update the effect
on the Text object.
The HTML Page that displays the JavaFX applet contains the JavaScript code and the HTML
form used to interact with the applet. Let's see how things operate in there:
F The JavaScript javafx() function —the JavaScript function javafx() , found in the
<script/> block, is used to initialize the applet on the web page. We have added
id:"js2jfx" to the parameter map as a value that will be used as a reference
identifier for the JavaFX applet object. This makes it easy to look up the object
representing the applet from the JavaScript document object model (DOM).
Search WWH ::

Custom Search