engine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override
public void handle(WebEvent<String> t) {
});
further. Instead of telling the user how
to do something, we could actually do
it for them. We could have a link that
makes the app perform the action that
the help text is talking about.
Of course, doing this sort of automation requires code on the JavaScript side
to be able to access code
on the Java side, which isn’t
possible yet. (Such a feature might come in a future
release of JavaFX.) However,
there is a clever workaround.
JavaScript code can call the
standard alert() function. The
WebEngine lets you create
a callback handler to deal
with alert events. Rather
than opening up an actual alert dialog,
we can use this function as a way for the
JavaScript side to communicate with
the Java side. In this case, we just want
to know when the user clicked the link;
then we can update the GUI.
On the markup side, we just need a
link that has a JavaScript URL:
On the Java side, I created a handler
for the alert event, as shown in Listing 9.
YOUR
LOCAL JAVA
USER GROUP
NEEDS YOU
JAVA IN ACTION
Conclusion
HTML, CSS, and JavaScript
are very powerful technolo-
gies, and now we can embed
these technologies in our
Java apps to make them do
new and interesting things.
This article just barely
touches on the possibilities.
A few other things you might
want to try include embedding an RSS
reader, caching Web pages for offline
reading, or creating an entirely Web-
based interface that runs locally as a
double-clickable Java app. The possibili-
ties really are endless. </article>
Find your JUG here
JavaFX 2.0 promises
to reinvent how
we create rich
client applications.
ABOUT US
blog
<a href="javascript:alert
('movies')">Do it for me</a>
LEARN MORE
•;JavaFX
•;Josh on Design blog