Java Reference
In-Depth Information
refreshCountdown)),
new KeyFrame(Duration.seconds(refreshCountdown), new
KeyValue(countDown, 0))
);
The rest of the code creates a
ChangeListener
that responds to
State.SUCCEEDED
. Once the
webEngine
(
WebEngine
) has finished retrieving
the XML, the change listener (
ChangeListener
) is responsible for parsing and ren-
dering the assembled web page into the
WebView
node. The following code parses
and displays the weather data by calling the
loadContent()
method on the
We-
bView
's
WebEngine
instance:
if (newValue != State.SUCCEEDED) {
return;
}
Weather weather = parse(webEngine.getDocument());
...// the rest of the inlined HTML
String countdownText = "<b id=\"countdown\"></b><br
/>\n";
webView.getEngine().loadContent(fullHtml
+ location.toString() +
timeOfWeatherTextDiv +
countdownText +
weather.htmlDescription);
To parse the XML returned by the
webEngine
's
getDocument()
method, the
org.w3c.dom.Document
object is interrogated. For convenience, I created a
parse()
method to walk the DOM to obtain weather data and return it as a
Weath-
er
object. See the Javadocs and Yahoo!'s RSS XML schema for more information on
data elements returned from a weather service.
17-4. Responding to HTML Events
Problem