Java Code

import java.awt.*;
import java.awt.event.*; 
import javax.swing.*;
public class TimedClock extends JApplet  implements ActionListener
{
    JLabel countdown;
    int count = 10;
    Timer timer;
    int DELAY = 800; 	// delay in milliseconds 	
    public void init( ) 
    {  
     	setLayout( new FlowLayout( ) ); 
     	countdown = new JLabel( String.valueOf( count ) );
     	countdown.setFont( new Font( "Serif", Font.BOLD, 46 ) );
     	add( countdown );
     	timer = new Timer( DELAY, this );
       timer.start( );
    }
    public void actionPerformed( ActionEvent ae )
    {
    	 Object src = ae.getSource( );
    	 if ( src == timer  && count > 0 ) 
    	 {
    		 count = count - 1;
    		 countdown.setText( String.valueOf( count ) );
    	 }
    	 if ( count == 0 )
    	 {
    		 countdown.setText( "Blastoff!" );
    		 timer.stop( );
    	 }
   }
}

©2007- by E.S.Boese. All Rights Reserved