File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ref to outside event handler" Watch "ref to outside event handler" New topic
Author

ref to outside event handler

scott beveridge
Greenhorn

Joined: Mar 03, 2005
Posts: 11
Hi,

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.

Scott
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ref to outside event handler