When defining nested classes, is it possible to access the “outer” class’ methods? I know it’s possible to access its attributes, but I can’t seem to find a way to use its methods.
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && //<-- Here I'd like to
} // reference a method
}); //from the class where
//addMouseListener() is defined!
Thanks
As your inner class is non-static, all methods of the outer class are automatically visible to the inner class, even private ones.
So, just go ahead and call the method that you want.
For example,
For more on this, see the Sun Tutorial on Nested Classes.