Handling Mouse Clicks
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access