Java Reference
In-Depth Information
2.
Packaging for browser deployment
—to get the application deployed as a JavaFX
applet, it must be packaged as such. To do this, we will use the
javafxpackager
tool (see the recipes
Building
and
packaging
your
app
using
javafxpackager
and
Packaging
your
app
as
an
applet
in this chapter). As we have seen in the previous
recipes, this step will yield a JAR file, a HTML file with the bootstrap JavaScript, and
a browser JNLP file.
3.
The HTML page
—create an HTML file which will embed both the applet and an HTML
form that controls the applet. Copy the bootstrap JavaScript stub, generated in
previous step, and add it to the HTML file, as shown next. Modify the JavaScript code
by adding an
id
attribute to the
javafx()
parameter. Also, create a new function
named
update()
that will control the interaction between the JavaScript and the
JavaFX applet:
<html>
…
<body>
<script src="http://dl.javafx.com/1.2/dtfx.js"></script>
<script>
// stub from packaging step
javafx(
{
archive: "js2jfx.jar",
width: 800,
height: 100,
code: "JavaScript2JavaFXDemo",
name: "js2jfx",
id:"js2jfx"
}
);
// added function to control JavaFX
function update(color) {
var js2jfx = document.getElementById("js2jfx");
js2jfx.script.textContent =
document.getElementById("msg").value;
js2jfx.script.textFont =
document.getElementById("font").value;
...
js2jfx.script.applyEffect(
document.getElementById("effect").selectedIndex
);
}
</script>
<hr/>
<form>


