This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I am using eclipse with windows builder plugin to develop my desktop application. The plugin used is generating the entire code into a single java file for gui.Now, I want to have the separate file for event handling.
Lets say we have one button and one textfield (code generated in file-Main.java),on click of button, the textfield should be filled with "Hello" .
For that we need to add actionListener to button and need to create an anonymous class and add method actionPerformed(),I want to have this class implementing ActionListener in separate java file(to separate the code we need to have the reference of the button and textfield in event handling class).How to get that reference.
you handle events 4 ways that i know of
1. implement the listeners. you will find this can get long and complicated with lots of if else statements
2. anonymous inner class
3. named inner class //my favorite so far
4. a separate top level class.
i misunderstood your question. you can do that a couple different ways also
1. pass a reference to "this" to the listener and make a variable package access so the listener can access it
2. pass a reference to "this" to the listener and supply get methods //i would go with 1 instead
in other word you have to write a constructor for your event handler sort of like this
there might be other ways i am unaware of
of course if your main class and the listener class are in different folders it kind of complicates things
you will have to do imports, and option 1 would change to making the variables pulic.