import java.awt.event.*;
import javax.swing.*;

/**
 * A ClickAction object can be used to programmatically
 * generate a button click.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class ClickAction extends AbstractAction
{
    private static final int    DELAY = 50; // millis
    
    private AbstractButton       button;
    

    /**
     * Explicit Value Constructor.
     *
     * @param button   The button to click
     */
    public ClickAction(AbstractButton button)
    {
        super();
        this.button = button;
    }

    /**
     * Handle an actionPerformed() message (required by AbstractAction).
     * Specifically, give the focus to and click the button.
     *
     * @param evt  The ActionEvent that generated the message.
     */
    public void actionPerformed(ActionEvent evt)
    {
        button.grabFocus();
        // Programmatically perform a "click". This does the same
        // thing as if the user had pressed and released the button.
        //The button stays visually "pressed" for DELAY milliseconds.
        button.doClick(DELAY);
    }
}
