aspose file tools
The moose likes Swing / AWT / SWT and the fly likes How to refer Outerclass from its innerclass Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "How to refer Outerclass from its innerclass" Watch "How to refer Outerclass from its innerclass" New topic
Author

How to refer Outerclass from its innerclass

prav ford
Greenhorn

Joined: Apr 28, 2004
Posts: 16
My code:
class x
{
this.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
//I NEED TO REFER TO CLASS X HERE.
}
});

From inside the mouseClicked, i need to get a reference to 'class x'
I should be able to do this-> x.get...();
I could have also done
class x extends Mou..... and implemented all methods...but i dont want it in that way.
Can anybody please help.
Kim Baddeley
Greenhorn

Joined: Nov 06, 2003
Posts: 6
The technique I use (not sure if it is the best way) is from the inner class call a method in class x.
So your example could be extended as....
class x
{
this.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
mouseClicked_actionPerformed(e);
}
});
private void mouseClicked_actionPerformed(ActionEvent e)
{
get....();
}
Cheers,
Kim
[ April 29, 2004: Message edited by: Kim Baddeley ]
C. Nimo
Ranch Hand

Joined: Mar 23, 2004
Posts: 82
Hi.
From the inner class - use

Nimo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to refer Outerclass from its innerclass
 
Similar Threads
DownCasting Generally
doubt in AWTEventMulticaster
How to refer Outerclass from its innerclass
Turn Based Strategy Games
non-static shades static