| Author |
Need to handle 2 event handlers in one class
|
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
Hi all,
I have a program using one Jlist where if I select the value using the mouse then the related values to the selected item are displayed in another Jlist on the form. This works fine but I noticed that I also need to handle thsi when the up-down keyboard keys are pressed.. I then implemented KeyListener as well as ListSelectionListener with all the required methods and I'm checking up KeyEvent up down etc..and in the keyPressed methods I want to place the same code as in the valueSelected method belonging to the ListSelectionListener interface but it does not have the required effect. before I post my code, can someone advise if I'm doing the right thing or can it be handled a better way?
Thanks,
Colm
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
|
Nothing prevents you from implementing different listeners in the same class. This should be fine.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
Thanks.
Yes I got this working.
In case anyone else wants to know, I added to separated event handlers to my JList. One for KeyListener and another for ListSelectionListener. I then had a class implementing both these interfaces with the code I wanted to fire in the keyPressed and keyReleased methods(implemented as part of the KeyListener interface) and the same code in the valueChanged method belonging to the ListSelectionListener Interface.
Thanks,
Colm
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8430
|
|
Colm Dickson wrote:
Yes I got this working.
Well done
And thank you for sharing your solution approach for future users.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
 |
|
|
subject: Need to handle 2 event handlers in one class
|
|
|