File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
Consider Paul's rocket mass heater.
subject: Determine JLists
It's not a secret anymore!