Forums Register Login

event handling

+Pie Number of slices to send: Send
Hi!
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)?
Thanks!
Altaf
+Pie Number of slices to send: Send
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.
All of the following truths are shameless lies. But what about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 697 times.
Similar Threads
JRadioButton in JTable
JTable
jtable
JTable
JTable(!!!)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:42:28.