import java.awt.*;
import java.awt.event.*;

/** PushImageButton extends ImageButton,
 * with a SpringyButtonLikeListener,
 * providing normal Button functionality.
 * @author David Geary
 */

public class PushImageButton extends ImageButton
implements Runnable {

/* --- Constructors that take an Image --- */

/** @param image -- the image to show.
 * @param text -- the text to show, or null.
 */

  PushImageButton (Image image, String text) {
     super (new SpringyButtonLikeListener (), image, 2, text);
  }

/** @param image -- the image to show.
 */

  PushImageButton (Image image) {
      this (image, null);
  }

/* --- Constructors that take a DrawImage --- */

/** @param drawImage -- the image to show.
 * @param text -- the text to show, or null.
 */

  PushImageButton (DrawImage drawImage, String text) {
     super (new SpringyButtonLikeListener (), drawImage, 2, text);
  }

/** @param drawImage -- the image to show.
 */

  PushImageButton (DrawImage drawImage) {
      this (drawImage, null);
  }

  private ActionListener actionListener = null;

/** Caller may add or remove an ActionListener,
 * same functionality as conventional awt.Button.
 */

  public synchronized void addActionListener (ActionListener al) {
      actionListener = AWTEventMulticaster.add (actionListener, al);
  }

  public synchronized void removeActionListener (ActionListener al) {
      actionListener = AWTEventMulticaster.remove (actionListener, al);
  }

/** Notify any listeners,
 * We **MUST** use a separate Thread to notify listeners,
 * so we and our calling event handler can immediately return.
 * Otherwise,
 * if the event listener happens to launch a modal dialog,
 * we don't wrap up for a long time,
 * and the event will be gone by the time we return,
 * causing the event distributor to throw a NullPointerException!
 */

  public void processAction () {
      if (null != actionListener)
          new Thread (this).start ();
  }

  public void run () {

	try {
	  actionListener.actionPerformed
	      (new ActionEvent
		  (this,
		   ActionEvent.ACTION_PERFORMED,
		   this.getText ()));


    } catch (Exception exc) { System.out.println ("failed processAction:"+exc); exc.printStackTrace (); }
  }
}
/* <IMG SRC="/cgi-bin/counter">*/
