Anonymous Inner Classes need to override their existing methods?

So I created an anonymous Inner Class via

    obj.addMouseListener(new MouseListener()

but because it gave me an error (it wanted me to implement at least 4 methods with names like mouseReleased, mouseClicked, etc. As I assumed the class didn't properly extend/implement the MouseListener, I stumbled upon another SO article (How can an anonymous class use "extends" or "implements"?) where I understood that anonymous Inner Classes always extend/implement a superclass (right?). So I continued my search for the answer and stumbled upon another SO article (I'm having trouble choosing when to use a MouseListener object) which is not really related to my problem, but I saw the owner of the thread write these lines of code

    @Override public void mouseExited(MouseEvent e) {}
    @Override public void mouseEntered(MouseEvent e) {}
    @Override public void mouseReleased(MouseEvent e) {}
    @Override public void mousePressed(MouseEvent e) {}

Is this what I have been missing? I already tried to @override the entire class at once but that just gave me another error on top. I can see how this would solve the problem, but it just looks very messy to me.

It basicly comes down to 2 questions; is what I've just written/discovered true, and is this the way to solve my problem and if this is the solution, is there another (cleaner) solution?

Jon Skeet
people
quotationmark

MouseListener is an interface - it doesn't have any method implementations, so if you're going to use that as the basis of your anonymous inner class, you need to provide implementations for everything.

If you just want to provide implementations for some of the methods, you should extend MouseAdapter instead - that provides no-op implementations, so you can just override the ones you want.

people

See more on this question at Stackoverflow