//Brad Culberson 04.23.98
//Draws a smiley face...

import java.awt.*;
import java.applet.Applet;

public class MyApplet10 extends Applet implements Runnable
   {int frameNumber = -1;               
    int delay;                          
    Thread animatorThread;
    boolean frozen = true;
    Font font=new Font("TimesRoman",Font.BOLD,36);
    String framestr = "";



    public void init()
       {String str;
        int fps = 10;                   
        str = getParameter("fps");      
        try                               
         {if (str != null)
           {fps = Integer.parseInt(str);}
          }                             
        catch (Exception e) {}           
        delay = (fps > 0) ? (1000/fps): 100;
        }                                   

  

    public boolean mouseDown(Event e, int x, int y)
       {if (frozen)
         {frozen = false;
          start();}
        else
         {frozen = true;
          stop();}
        return true;
        }

    public void start()
       {if (frozen) { }                  
        else                              
         {if (animatorThread == null)    
           {animatorThread = new Thread(this);}  
          animatorThread.start();             
          }                                   
        }

    public void run()
       {setBackground(Color.white);
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
        long startTime = System.currentTimeMillis();             
        while (Thread.currentThread() == animatorThread)        
           {frameNumber++;                             
            framestr = "Frame " + frameNumber;           
            repaint();                                   
            try                                        
             {startTime += delay;
              Thread.sleep(Math.max(0,
                                    startTime-System.currentTimeMillis()));
              }
            catch (InterruptedException e) {break;}   
            }                                           
        }                                          

    public void paint(Graphics g)
       {g.setColor(Color.blue);	  
        int xstart = size().width/2;	
	g.drawOval(xstart-frameNumber,20,frameNumber,frameNumber);
	g.drawOval(xstart+frameNumber-frameNumber,20,frameNumber,frameNumber);
	g.drawOval(xstart-frameNumber/6,frameNumber+40,frameNumber/3,frameNumber/3);
	g.drawArc(xstart-frameNumber/2*3/2,frameNumber+(frameNumber/3)+60,frameNumber*3/2,frameNumber/3,180,180);
        }

    public void stop()
       {animatorThread = null;}  
    }                           
