
import java.awt.*;
import java.util.*;
import java.net.*;
import java.io.*;

public class Ticker extends DBAnimationApplet {

  public void initQuotes() {} 

  public void initAnimator() {
    String att = getParameter("delay");
    if (att != null) {
      setDelay(Integer.parseInt(att));
    }
    watch = getParameter("watch");
    if (att != null) {
      StringTokenizer tk = new StringTokenizer(watch); 
      Vector v = new Vector(); 
      while (tk.hasMoreTokens()) {
	v.addElement(tk.nextToken()); 
      }
      n = v.size(); 
      symbol = new String[n]; 
      quote = new String[n]; 
      for (int i = 0; i < n; i++) {
	symbol[i] = (String) v.elementAt(i);  
	quote[i] = "0"; 
      }      
    }
    url = getDocumentBase();
    initQuotes(); 
    updateQuotes(); 
    text1 = text2; 
    x = d.width;
    y = font.getSize();
  }

  public void paintFrame(Graphics g) {
    g.setColor(Color.black);             
    g.fillRect(0,0,d.width,d.height);    
  
    // set the font and color, and draw the text
    g.setFont(font);                     
    g.setColor(Color.green);             
    g.drawString(text1 + text2, x, y);            
  
    // get the font metrics to  determine the length of the text
    FontMetrics fm = g.getFontMetrics(); 
    int length = fm.stringWidth(text1);   
  
    // adjust the position of text for the next frame
    x -= offset;                         
  
    // if the text is completely off to the left end
    // move the position back to the right end
    if (x < -length) {                    
      x = 0;   
      text1 = text2; 
      updateQuotes();       
    }                   
  }

  protected synchronized void updateQuotes() {
    StringBuffer sb = new StringBuffer(); 
    for (int i = 0; i < n; i++) {
      sb.append(symbol[i] + " " + quote[i] + "    "); 
    }
    text2 = sb.toString();
  }

  protected String text1, text2;         
  protected Font font = 
    new java.awt.Font("Helvetica", Font.BOLD, 24);  
  protected int speed = 100;     
  protected int offset = 1;      
  protected int x, y;            
  protected int n; 
  protected String symbol[], quote[]; 
  protected URL url; 
  protected String watch; 
}
