11.1. Handling Events with a Separate Listener

Suppose you want to create an applet that, when the user clicks in it, prints the click location in the Java console. (Recall that you can bring up the Java console by means of the Communicator or Communicator/Tools menu in Netscape and by means of the View menu in Internet Explorer.) To accomplish this task, you would first look at the available listener types in Section 11.5 and determine that MouseListener is the listener type that corresponds to mouse button actions and that MouseAdapter is an implementation with empty versions of the MouseListener methods. Section 11.5 would also tell you that mousePressed is the method that is triggered when the button is first pressed, that the method takes ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.