• Post Reply Bookmark Topic Watch Topic
  • New Topic

Action Listener for Combo box  RSS feed

 
Roberto Diaz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to implement a action listener for a combo box.
This code is in a class file say X.java :
/** some code **/
operCombo.addActionListener(new aListener()) ;
/** some code **/
I have created a new class file say Y.java, for aListener
class aListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// Some code
}
}
My problem is how do I make the Y.java recognize the ComboBox
which has been declared in X.java

Any ideas ??
Thanks.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reference returned by actionEvent.getSource() is the reference to the ComboBox.
If you want to listen only to events that indicate a selection change of the combo box, you should use an ItemListener instead of ActionListener.
Chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!