my guess would be that you did something like this:
public class MyClass extends JPanel implements ActionListener() {
private JButton button;
public void actionPerformed( ActionEvent e ) {
System.out.println( "# 1" );
}
public static void main( String args[] ) {
button = new JButton( "Ok" );
button.addActionListener( this );
// ... lots of code here
button.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) { System.out.println( "# 2" );
}
});
getContentPane().add( button );
}
}
Hmm.. but I think even that would just add the nested action listener.
Normally this means that you have added an actionlistener twice or added an actionListener in another listener.
1. Adding an actionListener twice.myTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
doStuff();
}
});
//... buncha other code ...
myTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
doStuff();
}
});
In this case doStuff() will be called twice for each event.
2. Adding an ActionListener in another listener.myTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
otherTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("Hello");
}
}
}
}
In this case, each time the event fires on myTextField, another actionListener is added to otherTextField. So, the first time 'Hello' will print once, the next time twice, 3 times,...