Java Reference
In-Depth Information
exception occurs. In a serious application, an error diagnosis should be performed
and a repair should be started.
To enable links, we augment class
SimpleHTMLFrame
to
HTMLViewer
by adding
code at two positions indicated by comments in
SimpleHTMLFrame
.Atthe first
position we add
LinkLis lili =
new
LinkLis();
ediPane.addHyperlinkListener(lili);
At the second position we add the implementation of the hyperlink listener as an
internal class:
private class
LinkLis
implements
HyperlinkListener
{
public void
hyperlinkUpdate(HyperlinkEvent hylevt)
{
try
{
if
(hylevt.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
URL newPage = hylevt.getURL();
ediPane.setPage(newPage);
}
}
catch
(Exception ex)
{
System.out.println("Problems with hyperlink-listener");
}
}//
method
}//
internal class
We do not list the resulting program
HTMLViewer
;itcan be downloaded from the
topic's home page. It can, for example, be used to display HTML-formatted help or
manual pages. Still, we miss some features when using the viewer. One of them is
a 'Back'-function which re-displays the previous HTML page. In the next section
we shall extend the viewer to a simple web browser which contains this feature.
22.3
■
A simple web browser
We now extend the application of the previous section to a simple web browser.
!
Recall that HTML-formatted web pages can be displayed only in the way that is
supported by the HTML interpreter of the current Java system. The application
lacks a number of security checks that should be added when used for other
purposes.
Our application
ITSBrowser
uses a
JEditorPane
to display the web pages. The
pane is embedded into a scroll pane, so that large pages can also be displayed. The
scroll pane is centrally embedded into a frame. Our browser has some control
Search WWH ::
Custom Search