package myWidgets;//======================================================================//  PROJECT:            _programming.java_//  FILE:               WordPro.java//  PURPOSE:            Chapter 11 lablet//  VERSION:            2.0//  TARGET:             Java v1.1//  UPDATE HISTORY:     2.0     12/4/98    1.1 event model//                      1.0     7/28/97    the version in _p.j_//======================================================================//------------------------------ IMPORTS -------------------------------	import java.awt.*; //======================= AnimatedButton CLASS =========================/** * This class implements an animated version of GraphicButton. * images[0] is the down picture--the rest are for the animated up state. * Requires at least three images for animation. */public class AnimatedButton extends GraphicButton implements Runnable{    private long    delayTime;    private Thread  myThread;    private boolean goingDown = false;	    //------------------------ Constructors ----------------------------        public AnimatedButton(Image[] imgs, String label, long delayMs)    {        super(imgs, label);        delayTime = delayMs;        myThread = new Thread(this);        myThread.start();    }	    public AnimatedButton(Image[] imgs, long delayMs)    {        this(imgs, null, delayMs);    }        //---------------------- Thread handlers ---------------------------        /**     * Start the animation thread.     */    public void start()    {        if (myThread == null)        {            myThread = new Thread(this);            myThread.start();        }    }	    /**     * Cycle through the up pictures when needed.     */    public void run()    {        while (myThread != null)        {            try            {                Thread.sleep(delayTime);            }            catch (InterruptedException e)            { }                        // Do nothing this turn if this button is down or if            // no animation is possible.            if ((curImage == 0) || (theImage.length == 2))            {                continue;            }                        if (goingDown)            {                if (curImage == 1)                {                    curImage++;                    goingDown = false;                 }                else                {                    curImage--;                }            }            else            {                if (curImage == theImage.length - 1)                {                    curImage--;                    goingDown = true;                 }                else                {                    curImage++;                }            }                    repaint();        }    }        /**     * Stop the animation thread.     */    public void stop()    {        if ((myThread != null) && myThread.isAlive())        {            myThread.stop();        }        myThread = null;    }}