import java.awt.*;
import java.applet.*;

public class RText2a extends Applet implements Runnable
{
 String teksti[] = new String[4];
 int ftkoko, a, y;
 Thread th;
 int ftr = 255, ftg = 0, ftb = 0, bgcolor;
 Font fonti;
 char aletter[] = new char[2];
 double x;
 Graphics gr;
 Dimension d = new Dimension();
 Image image;
 FontMetrics fm;
 
 public void init()
 {
  teksti[0] = getParameter("teksti[0]");
  teksti[1] = getParameter("teksti[1]");
  teksti[2] = getParameter("teksti[2]");
  teksti[3] = getParameter("teksti[3]");
  ftkoko = Integer.valueOf(getParameter("ftkoko")).intValue();
  bgcolor = Integer.valueOf(getParameter("bgcolor")).intValue();
  setBackground(new Color(bgcolor));
  d = size();
  image = createImage(d.width, d.height);
  gr = image.getGraphics();
  gr.setFont(new Font("Arial",Font.BOLD,ftkoko));
  fm = gr.getFontMetrics();
  	
 }
 public void start()
 {
  if (th == null) {
  th = new Thread(this);
  th.start(); }
  }

 public void run()
  { int X;
    x = (double)(d.width + fm.stringWidth(teksti[a]) + 100);
     
   while (true)
   {
    gr.setColor(getBackground());
    gr.fillRect(0, 0, d.width, d.height);
    X = (int)x;
    gr.setColor(new Color(ftr, ftg, ftb));
    
    showStatus(teksti[a]);
    for (int i=(teksti[a].length()-1); i >-1; i--)
    {
     aletter[0] = teksti[a].charAt(i);
     y = (int)(bounds().height/1.5);
     X = X-fm.charWidth(teksti[a].charAt(i))-1;
     
     gr.drawChars(aletter, 0, 1, X, y);
    }
     x -= 5;
     if (x < 0)
      { x = d.width+fm.stringWidth(teksti[a]) + 100;

        ftr = (int)(Math.random()*255);	// satunnaiset värit
     ftg = (int)(Math.random()*255);
     ftb = (int)(Math.random()*255);

     a++;				// vaihtaa teksti
  if (a == 4)
  a = 0; }     
   super.repaint();
     
   try {				// viive
     th.sleep(50); }
     catch (InterruptedException e) {}
     
     }
   }

 public void update(Graphics g)
 {  
   g.drawImage(image, 0, 0, d.width, d.height, this);
  }

 public void stop()
  {
    th = null;
   }
 
}
