*
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 Android Security Essentials Live Lessons this week in the Android forum!
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).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ref to outside event handler
 
Similar Threads
can not find methods
setText() not working
change the texts to a different one in a JButton each time it is pressed.
how to access values from Jtextfields into an array ?
non-static var from static context