This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes ref to outside event handler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ref to outside event handler" Watch "ref to outside event handler" New topic

ref to outside event handler

scott beveridge

Joined: Mar 03, 2005
Posts: 11

Inside an event handler I want to send text to a seperate object. If I create the object inside the handler it works, but if the object is created by a different class it doesn't, even though the other class is public. How do I connect the method inside the handler to the object outside?

So I want to do this and it doesn't work,

But this works,

Thanks guys, this is tough at first but I'm slowly getting it.

Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
Where in your source is the declaration for innerclass? As long as it is within the mainProgram, you need to make an instance variable out of the textHolder, and addActionListener(new innerclass()); should be enough.

Of course, you need to connect it all to some gui. The textHolder will probably be an element of the gui, so make it an instance field there, and innerclass should also be contained in the main gui class (if you insist on using an inner class).
jQuery in Action, 2nd edition
subject: ref to outside event handler