A canonical form
Inner classes, the Swing event model, and the fact that the old AWT event model is still supported, along with new library features that rely on old-style programming, has added a new element of confusion to the code design process. Now there are even more different ways for people to write unpleasant code.
Except in extenuating circumstances, you can always use the simplest and clearest approach: Listener classes (typically written as inner classes) to solve your event-handling needs. This is the form used in most of the examples in this chapter.
By following this model you should be able to reduce the statements in your programs that say “I wonder what caused this event.” Each piece of code is concerned with doing, not type checking. This is the best way to write your code; not only is it easier to conceptualize, but it’s much easier to read and maintain.