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) {
        browser.showDocument(pageLink[current]);
    }

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 ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.