Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of


This example works exactly the same as the Click example, however, here we use an inner class, MA,...

that extends java.awt.event.MouseAdapter .

The advantage is, that we only have to specify the methods that we're interested in. In this case, mouseClicked.

Apart from the inner class, there are 2 main differences between this and the Click example :

1. There's NO
implements java.awt.event.MouseListener

because the MouseAdapter class implements it, it contains the 5 mouse methods.


2. It says the inner class, MA, will listen :
  addMouseListener ( new MA( ) ) ;

instead of :
  addMouseListener ( this ) ;


Inner classes are often used as shown, extending adapter classes, but in a more general sense they can be used as helper class, helping the main class.




Inner class methods have access to all members of the containing(outer) class.


After compiling there is an extra binary file, Adapt$MA.class .


What we actually do here is OVERRIDE MousAdapter's mouseClicked method.