<AWT Dev> RFE: Listeners with Adapter-classes should have empty default methods
Andreas Lundblad
andreas.lundblad at gmail.com
Sat Aug 23 23:42:28 UTC 2014
For listener interfaces where it's common to just implement one or two
methods, there are corresponding Adapter classes with empty method
implementations. (For example: MouseListener/MouseAdapter,
KeyListener/KeyAdapter, ComponentListener/ComponentAdapter, ...)
The Adapter classes are really convenient for obvious reasons. However, due
to the constraint of single inheritance, they can't be used together with
each other. That is, if I want to listen to key presses
(KeyListener.keyPressed) and mouse clicks (MouseListener.mouseClicked) I'm
doomed to either
1) choose to extend one of the adapters and clutter my code with empty
method implementations for the other, or
2) Extend the two adapters in two separate classes and instantiate two
separate listener objects (which gets slightly messy if they need to share
some state).
Therefor I propose to add empty default implementations for these types of
listener interfaces. This would allow me to for instance implement
KeyListener and MouseListener and just override keyPressed and mouseClicked.
Some basic grepping yields the following list:
ComponentListener
ContainerListener
DragSourceListener
DropTargetListener
FocusListener
HierarchyBoundsListener
InternalFrameListener
KeyListener
MouseListener
MouseMotionListener
PrintJobListener
WindowListener
best regards,
Andreas Lundblad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/awt-dev/attachments/20140824/6ccc9d43/attachment.html>
More information about the awt-dev
mailing list