import java.awt.*;
import java.applet.*;

public class CountDown extends Applet implements Runnable{
    int counter;
    Thread cd;
    Font f1 = new Font("Helvetica",Font.BOLD,36);
    AudioClip tick;
    AudioClip bang;

    public void init() {
        tick = this.getAudioClip(getCodeBase(), "tick.au");
        bang = this.getAudioClip(getCodeBase(), "bang.au");
    }

    public void start() {
        setBackground(Color.white);
        counter = 10;
        cd = new Thread(this);
        cd.start();
    }

    public void stop() { cd = null;}

    public void run() {
        for (; counter>0; counter--) {
            if (cd==null) return;
            repaint();
            tick.play();
            try{Thread.sleep(1000);} catch (InterruptedException e){}
        }
        setBackground(Color.red);
        repaint();
        bang.play();
    }

    public void paint(Graphics g) {
        g.setFont(f1);
        if (counter > 0)
            g.drawString(String.valueOf(counter),25,50);
        else
            g.drawString("Bang",10,50);
    }
}
