//File:	Surprise3.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Surprise3 extends Applet
{
	//Exploding and imploding balloons

 	public void init()
 	{
 		setBackground (Color.white);
 	}
 	 	
 	public void paint (Graphics g)
  	{
  		Dimension size = getSize();
    		
    		int 	diameter = 0,
        			w = size.width,
        			h = size.height,
        			cmin = (int)Math.min(w, h);

    		g.setColor(Color.yellow);
    		while (diameter < cmin)
    		{
    			g.fillOval((w-diameter)/2,  (h-diameter)/2, 
                 				diameter,  diameter);
      			diameter++;
      			
      			try
      			{
      				Thread.sleep(10);               // sleep for 10 msec
      			}
      			catch (InterruptedException t)
      			{
      			}
    		}

    	    	Font current = getFont();
    		FontMetrics metrics = getFontMetrics (current);
                int ws = metrics.stringWidth("Surprise!");
                int hf = metrics.getHeight();
                    		
    		g.setColor(Color.red);
    		g.drawString("Surprise!", (w-ws)/2, (h+hf)/2);
	
    		try
    		{
    			Thread.sleep(1000);               // sleep for 1 sec
    		}
    		catch (InterruptedException t)
    		{
    		}
    		
    		while (diameter > 1)
    		{
    			//The following draws circles in yellow,
    			//pauses, then redraws them in white (the background color),
    			//thus effectively erasing them.  It then changes the color
    			//back to yellow and repeats the process for a circle
    			//of diameter one less than the previous one.
    			
    			g.setColor(Color.yellow);
    			g.fillOval((w-diameter)/2,  (h-diameter)/2, 
                 				diameter,  diameter);
      			try
      			{
      				Thread.sleep(10);               // sleep for 10 msec
      			}
      			catch (InterruptedException t)
      			{
      			}
      		
    			g.setColor (Color.white);
    			g.fillOval((w-diameter)/2,  (h-diameter)/2, 
                 				diameter,  diameter);
                 				
                 	diameter--;
      			
    		}

    		repaint();	//calls update() which CLEARS THE WINDOW,
				//then calls paint()
    	}
}