Forums Register Login

Determine JLists

+Pie Number of slices to send: Send
Hi Coders!
take a look:
[code]
JButton a = new JButon("A");
JButton b= new JButon("B");
// .....
a.setActionCommand("A");
b.setActionCommand("B");
//......
if(if source.getCommandAction() == "A"){
// its A
}else
if{ source.getCommandAction() == "B")
// its B
}
how can i do the same or semilar determine action with more than one JList and only one listener???
Thanks


[This message has been edited by Shay Gaghe (edited November 14, 2001).]
+Pie Number of slices to send: Send
HI,
Short answer: you can't. ActionCommand is only valid for buttons. You can however use class variables:
JList list1, list2;
if( source.getSource() == list1 )
{
// We are dealing with first list
}
else if( source.getSource() == list2 )
{
// We are dealing with second list.
}
Another approach you can use is to make use of anonymous classes and assign one to each JList. Then inside of each listener method you can call another class method that can keep track of all the list IDs.
Regards,
Manfred.
You’ll find me in my office. I’ll probably be drinking. And reading 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 796 times.
Similar Threads
Graphic JButon on JPanel
Need help with adding an action on JButon
BoxLayout
Calculator Problem
instanceof operator
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:02:46.