ActionListener run automatically problem
Hi, something weird happen to my program.
Before I click the button, it seems that the program run my action listener automatically. The ....This shouldnt happen to appear on the console before button clicked...appear in the console before the button clicked.
What is wrong with the code?
and another weird thing happen the last else also shown in the console...but I only have 2 buttons.
Code:
......
buttonX.addActionListener(this);
buttonY.addActionListener(this);
public void actionPerformed(ActionEvent e) {
.....
System.out.println ([COLOR="Blue"]"This shouldnt happen to appear on the console before button clicked[/COLOR]");
if(e.getSource ()==buttonX)
System.out.println ("Answer 1")
else if (e.getSource()==buttonY)
System.out.println ("Answer 2")
else
[COLOR="Blue"] System.out.println ("This should not happen");[/COLOR]
......
}