Hi guys,

I have a question about action listeners and i've been searching forever but can't seem to find anything to help me. Basically, I have a Jbutton setup, but upon certain instances, when a boolean flag is set, i need to automatically invoke the button via code.

Example: I am creating a simple board game that requires AI. But the interface is all Jbuttons. So when it is the computer's turn, i need to be able to invoke the Jbutton (basically, I need to pretend the computer had a mouse and pushed the button itself), but i'm not sure how to go about doing that. Any help would be greatly appreciated .

I grabbed some sample code off java's website, perhaps someone could show me how it would work in this example?


public class SwingApplication implements ActionListener {
...
JButton button = new JButton("I'm a Swing button!");
button.addActionListener(this);
....

public void actionPerformed(ActionEvent e) {
numClicks++;
label.setText(labelPrefix + numClicks);
}
}

Thanks,
Mo