There's got to be a trick for using the "this" pointer of the parent object from an instance of an inner class, but I can't find it. (BTW it doesn't help in the research department that "this" is also an extremely common
word)
I'm coming from the C++ world and it seems that the use of inner classes is radically different between C++ and
Java. In C++ inner classes were literally classes defined within another class and therefore could be instantiated and used anywhere. In Java they seem to be tightly tethered to their parent class: instances can only exist within an instance of the parent and inner class objects can freely use the members of the owning parent object as if it actually was its parent. At first it seemed so strange, but I'm really liking it now.
This is all fine and dandy until I need to use "this". It seems that the "this" within the inner class is literally the object of that inner class instead of the parent object. I've tried super.this and super().this to no avail.
Here's what I'm trying to do:
My parent class is a JLayeredPane-derived class with various child components laid upon itMy inner class is a MouseAdapter-derived class
Within some functions of MouseAdapter I want to convert points from the coordinates of the main parent pane to the child components using SwingUtilities.convertPoint(...). That means I'm going to need to provide the component and the parent pane: and that means I need "this"!
But how do I do that?
I've gotten around this by passing "this" to the inner class' constructor and saving it as a member, but that's such a hack since Java integrates the parent and inner objects so tightly. There's got to be a slick and proper way of doing this.