Using External Listeners for Event Handling

Click in the applet to draw circles.

Make sure that Java is enabled in your browser

This applet uses an external class to handle events which occur when an user presses button on the mouse.

Java code for the applet itself: applet is a source of Mouse events.

Here is java code for the listener: the listener is defined as an external class CircleListener that receives Mouse events and responds by drawing blue circles on the applet. Note that CircleListener class extends an adapter class MouseAdapter. The MouseAdapter class helps by providing (empty) implementations for all methods in the MouseListener interface. For this reason, we can simply override one method (mousePressed) to provide the desirable implementation.