The last thing to take care of in the LinkRotator
applet is event handling. Whenever a user clicks the Go button, the web browser should open the website shown. This is done with a method called actionPerformed()
, which is called whenever the button is clicked.
The following is the actionPerformed()
method of the LinkRotator
applet:
public void actionPerformed(ActionEvent event) {
if (runner != null) {
runner = null;
}
AppletContext browser = getAppletContext();
if (pageLink[current] != null) {
browser.showDocument(pageLink[current]);
}
}
The first thing that happens in this method is that the runner
thread is stopped. The next statement creates a new AppletContext
object called browser
.
An AppletContext
object represents the environment in which the applet is being presented—in other words, the page it’s located on and the web browser that loaded the page.
The showDocument(
URL)
method loads the specified web address in a browser. If pageLink[current]
is a valid address, showDocument()
requests that the browser load the page.
18.117.7.212