import java.awt.*;
import java.applet.*;

public class RText2b extends Applet implements Runnable
{
 int line, yalku, yloppu;
 String text = new String();
 int a, y = 50, x;
 int bgcolor, fontsize, fontstyle, sleep;
 Thread th;
 int ftr = 255, ftg = 0, ftb = 0; // ensimäinen väri on punainen
 Font font;
 Graphics gr;
 Dimension d = new Dimension();
 Image image;
 String fontname;
 
 public void init()
 {
  line = Integer.valueOf(getParameter("line")).intValue();
  
  sleep = Integer.valueOf(getParameter("sleep")).intValue();
  
  fontsize = Integer.valueOf(getParameter("fontsize")).intValue();
  fontstyle = Integer.valueOf(getParameter("fontstyle")).intValue();
  fontname = getParameter("fontname");

  yalku = Integer.valueOf(getParameter("yalku")).intValue();
  yloppu = Integer.valueOf(getParameter("yloppu")).intValue();

  bgcolor = Integer.valueOf(getParameter("bgcolor")).intValue();
  setBackground(new Color(bgcolor));
  d = size();
  image = createImage(d.width, d.height);
  gr = image.getGraphics();
  font = new Font(fontname, fontstyle, fontsize);
  gr.setFont(font);

    	
 }
 public void start()
 {
  if (th == null) {
  th = new Thread(this);
  th.start(); }
  }

 public void run()
  {
   
   while (true)
   {    
   text = getParameter("text"+a); 
    
   super.repaint();
     
   try {				// viive
     th.sleep(sleep); }
     catch (InterruptedException e) {}
     
     }
   }

 public void update(Graphics g)
 {
    gr.setColor(getBackground());          //tyhjä kuva
    gr.fillRect(0, 0, d.width, d.height);
    gr.setColor(new Color(ftr, ftg, ftb));
    
    showStatus(text);
   x = (bounds().width - getFontMetrics(font).stringWidth(text))/2; 
       // keskitä text
     y--;
   gr.drawString(text, x, y);  // tulostaa teksti 
   if (y < yloppu)
    {
     y = yalku;


  ftr = (int)(Math.random()*255);	// satunnaiset värit
  ftg = (int)(Math.random()*255);
  ftb = (int)(Math.random()*255);    
  

   a++;					// vaihda text
   if (a == line)
   a = 0; }
  g.drawImage(image, 0, 0, d.width, d.height, this);
  }

 public boolean imageUpdate(Image image, int info, int x, 
          int y, int width, int height)
 {
  return true;
 }

 public void stop()
  {
   th = null;
   }
  
}
