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
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