import java.awt.*;
import java.util.*;
/**
  * the class that forms structure so that words can be displayed
  *
  * @author Aleksey Babeyev,Jim Congdon,Eric Hwuang,Corey Miller, & Jack Wen
  * @see HarpoonGui
  */
public class TextPanel extends Container
{ 
  TextPanel()
  { /**
    * constructor for class
    */
    setLayout(new FlowLayout());
    myImages = new Vector();  
    myOutline = new TextArea("",50,105,3);
    add(myOutline);
  }

  void setImage(Image im)
  { /**
    * sets myImage
    */
    myImage = im;
  }

  public void update(Graphics g)
  { /**
    * calls paint method
    */
    paint(g);
  }

  public int getCompIndex(Component comp)
  { /**
    * returns index of component
    */
    int k;
    for(k=0;k<getComponentCount();k++)
    {
      if(comp == getComponent(k)) return k;
    }
    return -1;
  }

  public void paint(Graphics g)
  { /**
    * paints image to screen
    */
    if (myImageBuffer == null)
    {
      myImageBuffer = this.createImage(getSize().width,getSize().height);
      myGraphics = myImageBuffer.getGraphics();
    }

    if (myImage != null)
      //if(1==2)
    {
      myGraphics.drawImage(myImage, 0, 0, getSize().width,
			   getSize().height,
			   getBackground(), this);
    }

    super.paint(myGraphics);
    g.drawImage(myImageBuffer, 0, 0, null);

    validate();
  }

  private TextArea myOutline;
  private Vector    myImages;
  private Image     myImageBuffer;
  private Graphics  myGraphics;
  private Image     myImage;
}
