/*  
    Kwan Hoi Ching, Eddie 
    Final Year Project 1995-1996, CSD, HKUST 
    25-02-96 

    Text Scrolling Animation.
*/

import java.awt.*;

public class ScrollingText extends java.applet.Applet implements Runnable {

	char separated[];
	String s = null;
	Thread killme = null;
        int x_coord, y_coord;

        double pulling_num = 0.0;

  public void init() {

        setFont(new Font("TimesRoman",Font.BOLD,24));
	s = getParameter("text");
	if (s == null) {
            s = "defaults";
	}

	separated =  new char [s.length()];
	s.getChars(0,s.length(),separated,0);

  }

  public void start() {
        if(killme == null) {
          killme = new Thread(this);
          killme.start();
	}
   }

  public void stop() {
	killme = null;
  }

  public void run() {
        while (pulling_num < 1 && killme != null) {
          try {Thread.sleep(20);} catch (InterruptedException e){}
          repaint();
	}
	killme = null;
  }

  public void paint(Graphics g) {

        int i;
        int width = 0;
        FontMetrics fm = g.getFontMetrics();

        if (pulling_num < 1) pulling_num += 0.05;

        for(i = 0; i < s.length(); i++) {
          if (i != 0) width += fm.charWidth(separated[i-1]);
 
          x_coord = (int) (pulling_num*width);
          y_coord = 40;
          g.drawChars(separated, i, 1, x_coord, y_coord);
        }
        
  }
 
}

