The name (and javadocs) imply that MouseAdapter
is an adapter (the design pattern). But I don\'t see it as such - it doesn\'t adapt anything to anything, at fir
As other answers have said, it's not a GoF Adapter pattern. The main purpose of it is to enable one to implement MouseListener
(or MouseMotionListener
) by over-riding just the desired methods in MouseAdapter
(often just mouseClicked()
) rather than having to create pointless empty implementations of all the other methods. It therefore saves a lot of unnecessary code, especially when using anonymous event listeners. For example (taken from here)
someObject.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
...//Event listener implementation goes here...
}
});