FileDocCategorySizeDatePackage
Animator.javaAPI DocExample1690Thu Apr 03 15:16:08 BST 1997None

Animator

public class Animator extends Applet implements Runnable

Fields Summary
boolean
running
int
thisCell
Vector
cells
Thread
play
MediaTracker
theTracker
Constructors Summary
Methods Summary
public voidinit()


     

    String nextCell;
    cells = new Vector();
    theTracker = new MediaTracker(this);
    for (int i = 0; (nextCell = getParameter("Cell" + i)) != null ; i++) {
      Image img = getImage(getDocumentBase(), nextCell);
      cells.addElement(img);
      theTracker.addImage(img, i);      
    }
    
    // start loading the images
    theTracker.checkAll(true);
    play = new Thread(this);
    play.start();
    running = true;
  
  
public booleanmouseUp(java.awt.Event e, int x, int y)

  
    if (running) {
      play.suspend();
      running = false;
    }
    else {
      play.resume();
      running = true;
    }
    
    return true;  
          
  
public voidpaint(java.awt.Graphics g)

   
    g.drawImage((Image) cells.elementAt(thisCell), 0, 0, this);
    
  
public voidrun()

  
    for (thisCell=0; thisCell < cells.size(); thisCell++) {
    
      try {
        // make sure this cell is loaded
        theTracker.waitForID(thisCell);
        // paint the cell
        repaint();
        // sleep for a tenth of a second
        // i.e. play ten frames a second
        play.sleep(100);
      }
      catch (InterruptedException ie) {      
      }
    }
  
  
public voidstart()


    play.resume();

  
public voidstop()


    play.suspend();