import java.awt.*;

        // Displays two Labels in a Frame.
        // These are used as a two-digit countdown.
public class Countdown extends Frame {
    public Countdown(){
        final int width = 100, height = 75;
        setSize(width,height);
        setBackground(Color.white);

        // Use a FlowLayout to keep the digits together in the
        // centre of the frame.
        setLayout(new FlowLayout());
        // Set the font for the Frame.
        final int fontSize = 20;
        setFont(new Font("SansSerif",Font.BOLD,fontSize));

        // Add the digit labels to the frame.
        add(getHighDigit());
        add(getLowDigit());
    }

        // Give a countdown of the required number of seconds.
    public void countdown(int seconds){
        updateDisplay(seconds);

        // Tick away the seconds.
        try{
            // One second in milliseconds.
            final int oneSecond = 1000;
            while(seconds > 0){
                Thread.sleep(oneSecond);
                seconds--;
                updateDisplay(seconds);
            }
        }
        catch(InterruptedException e){
        }
    }

        // Show the number of seconds as two separate digits.
    protected void updateDisplay(int seconds){
        // Make sure seconds fits within two digits.
        seconds %= 100;
        // Extract the two components.
        int highDigit = seconds / 10;
        int lowDigit = seconds % 10;
        // Set the text of the two components.
        getHighDigit().setText(Integer.toString(highDigit));
        getLowDigit().setText(Integer.toString(lowDigit));
        // Make sure the display is updated.
        repaint();
    }

    protected Label getHighDigit(){
        return highDigitDisplay;
    }

    protected Label getLowDigit(){
        return lowDigitDisplay;
    }

    // The two labels used for the two digits.
    private Label highDigitDisplay = new Label("0",Label.CENTER);
    private Label lowDigitDisplay = new Label("0",Label.CENTER);
}
