Handling Mouse Clicks

The last thing to take care of in the Revolve applet is event-handling: Whenever a user clicks the Go button, the web browser should open the website that is listed. This is done with a method called actionPerformed(). The actionPerformed() method is called whenever the button is clicked. The following is the actionPerformed() method of the Revolve applet:

public void actionPerformed(ActionEvent evt) {
 if (runner != null) {
 runner = null;
 AppletContext browser = getAppletContext();
 if (pageLink[current] != null) {

The first thing that happens in this method is that the runner tHRead is stopped in the same way it was stopped in the applet's stop() method. 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() method of this object is called with a single argument: a URL object representing a World Wide Web address. If the page represented by pageLink[current] is a valid address, showDocument() is used to request that the browser load the page.