This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Determine JLists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Determine JLists" Watch "Determine JLists" New topic

Determine JLists

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
Hi Coders!
take a look:
JButton a = new JButon("A");
JButton b= new JButon("B");
// .....
if(if source.getCommandAction() == "A"){
// its A
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???

[This message has been edited by Shay Gaghe (edited November 14, 2001).]
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.
I agree. Here's the link:
subject: Determine JLists
jQuery in Action, 3rd edition