• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Determine JLists

 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic