This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Determine JLists" Watch "Determine JLists" New topic
Author

Determine JLists

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
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

Joined: Jan 09, 2001
Posts: 1492
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Determine JLists
 
Similar Threads
Graphic JButon on JPanel
Calculator Problem
BoxLayout
instanceof operator
Need help with adding an action on JButon