This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes event handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "event handling" Watch "event handling" New topic

event handling

Altaf Ahmad

Joined: Apr 24, 2002
Posts: 13
I had a conceptual question about Java event handling. When we implement event handling by extending classes or implementing interfaces, we end up having a different class handling events. How, then, is it possible to work with data (objects) of the class which is generating the events?
For example, say I have a JProgressBar and a JTable as objects in a class. When a user clicks on a row in the table, the progress bar's value should reflect the new table row selection. To access both the objects, we need to work in the class containing both of them. If we extend the JTable class or implement a selection interface in a new class, then we don't have access to the progress bar any more!
I'm sure I'm missing something or trying to do it the wrong way. Could anybody explain to me where I might be taking an incorrect approach (in the language or logically)?
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
if i understand your question correctly my suggestion is this:
first you can pass refernces to the new classes of the progressbar and the jtable so you can access both.
second and even better is just to use inner classes or even annonymous ones so you can access all the variabls you got in your main class.
create the event handling class (the listener) as an inner class inside the class you got the progrss bar and the jtable.
hope it helps.
I agree. Here's the link:
subject: event handling
It's not a secret anymore!