This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refer Outerclass from its innerclass

 
prav ford
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
From the inner class - use

Nimo.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic