Java Reference
In-Depth Information
final VBox leftArea = new VBox(10);
final TextField urlField = new TextField();
urlField.setOnAction((ActionEvent ae) -> {
String url = urlField.getText();
final Hyperlink jfxHyperLink = createHyperLink(url,
webEngine);
hyperLinksMap.put(url, jfxHyperLink);
HBox rowBox = new HBox(20);
rowBox.getChildren().add(jfxHyperLink);
leftArea.getChildren().add(rowBox);
webEngine.load(url);
urlField.setText("");
});// end of urlField setOnAction()
After the user clicks on a hyperlink the news retrieval is initiated. Once a successful
retrieve has occurred on the webEngine ( WebEngine ) object, you need to add a
ChangeListener instance to respond when the state property changes to
State.SUCCEEDED . With a valid state of State.SUCCEEDED, you begin to parse
the XML DOM returned from the WebEngine 's getDocument() method. Again, I
provided a convenience method called parse() to interrogate the Document object
representing the RSS news information.
RssFeed rssFeed = parse(webEngine.getDocument(),
webEngine.getLocation());
Next, you create an HTML page that will list the channel tile and the number of
total news headlines returned. After creating the HTML to display the RSS channel
title and the number of articles, you iterate over all the news headlines to build record
sets or rows. Each row will contain an HTML button labeled View to notify the We-
bEngine object of an alert containing the article's URL. When the WebEngine ob-
ject is notified, the OnAlert property will contain an event handler to render the en-
tire article in the frame in the lower-right split region. After the web page is assembled,
you call the newsBrief object's getEngine().loadContent() method to
render the page. Once it's rendered, you save the URL RSS feed ( RssFeed ) object to
the database by invoking the DBUtils.saveRssFeed(rssFeed) . As a conveni-
ence, the saveRssFeed() method will check for duplicates and not save them. The
following code loads the web page to be rendered and saves the newly added
rssFeed URL:
Search WWH ::




Custom Search