FileDocCategorySizeDatePackage
Animator.javaAPI DocExample2015Sat Sep 09 20:32:10 BST 2000None

Animator

public class Animator extends Applet implements MouseListener, Runnable

Fields Summary
boolean
running
int
thisCell
Vector
cells
Constructors Summary
Methods Summary
public voidinit()


     

    this.addMouseListener(this);
    
    String nextCell;
    MediaTracker theTracker = new MediaTracker(this);
    for (int i = 0; (nextCell = this.getParameter("Cell" + i)) != null ; i++) {
      Image img = this.getImage(this.getDocumentBase(), nextCell);
      cells.addElement(img);
      theTracker.addImage(img, i);
      // start loading the image in a separate thread
      theTracker.checkID(i, true);
    }
    
    // wait for all images to finish loading
    try {
      theTracker.waitForAll();
    }
    catch (InterruptedException e) {      
    }
    
  
public voidmouseClicked(java.awt.event.MouseEvent e)

  
    if (running) {
      this.stop();
    }
    else {
      this.start();
    }
          
  
public voidmouseEntered(java.awt.event.MouseEvent e)

public voidmouseExited(java.awt.event.MouseEvent e)

public voidmousePressed(java.awt.event.MouseEvent e)

public voidmouseReleased(java.awt.event.MouseEvent e)

public voidpaint(java.awt.Graphics g)

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

  
    for (thisCell=0; thisCell < cells.size(); thisCell++) { 
      if (!running) return;
        // paint the cell
        this.repaint();
        // sleep for a tenth of a second
        // i.e. play ten frames a second
      try {
        Thread.sleep(100);
      }
      catch (InterruptedException ie) {      
      }
    }
  
  
public voidstart()

    this.running = true;
    Thread play = new Thread(this);
    play.start();
  
public voidstop()

    this.running = false;