import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class TimerDemo extends Applet implements ActionListener
{
    Timer timer;
    JLabel display;
    int counter = 100;
    
    public void init ()
    {
	resize (250, 250);
	JButton play = new JButton ("Click to start");
	play.addActionListener (this);
	play.setActionCommand ("start");
	add (play);
	JButton end = new JButton ("Click to stop");
	end.addActionListener (this);
	end.setActionCommand ("stop");
	add (end);
	
	display = new JLabel ("100");
	add (display);

	ActionListener listener = new ActionListener ()
	{
	    public void actionPerformed (ActionEvent ae)
	    {
		counter--;
		display.setText ("" + counter);
		try
		{
		    Thread.sleep (500);
		}
		catch (InterruptedException m)
		{
		    ;
		}
	    }
	}
	;
	timer = new Timer (250, listener);

    }


    public void actionPerformed (ActionEvent e)
    {
	if (e.getActionCommand ().equals ("start"))
	{
	    counter = 100;
	    timer.start ();

	}
	else if (e.getActionCommand ().equals ("stop"))
	{
	    timer.stop ();
	}

    }



    protected static ImageIcon createImageIcon (String path)
    {
	java.net.URL imgURL = SoundDemo.class.getResource (path);
	if (imgURL != null)
	    return new ImageIcon (imgURL);
	else
	    return null;
    }
}
