import java.awt.*;
import java.applet.*;

public class RFade1 extends Applet implements Runnable
{
 String text = new String();
 int a, x, y, line, sleep;
 Thread th;
 int ftr = 0, ftg = 0, ftb = 0;		
 Font font;
 Graphics gr;
 Dimension d = new Dimension();
 Image image;
 int fontstyle, fontsize;
 String fontname;
 
 public void init()
 {
  d = size();
  image = createImage(d.width, d.height);
  gr = image.getGraphics();
  fontsize = Integer.valueOf(getParameter("fontsize")).intValue();
  fontstyle = Integer.valueOf(getParameter("fontstyle")).intValue();
  line = Integer.valueOf(getParameter("line")).intValue();
  sleep = Integer.valueOf(getParameter("sleep")).intValue();
  fontname = getParameter("fontname");
  setBackground(Color.black); 		// taustaväri:musta	
 }
 public void start()
 {
  if (th == null) {
  th = new Thread(this);
  th.start(); }
  }

  public void stop()
  {
   th = null;
   }

  public void run()
  {
   Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

   while (true)
   {
    text = getParameter("text"+a);	// vaihtaa text(param)

    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);

    font = new Font(fontname, fontstyle, fontsize);

    gr.setFont(font);

    ftr++; ftg++; ftb++;  // 0 0 0 - 255 255 255 eli mustasta
			  //		valkoiseksi
    if (ftr == 255 && ftg == 255 && ftb == 255)
   { ftr = 0; ftg = 0; ftb = 0;
     a++; }		// a++ vaihtaa text

  gr.setColor(new Color(ftr, ftg, ftb));
   
    if (a == line)		
    a = 0;
     
    x = (bounds().width - getFontMetrics(font).stringWidth(text))/2;
       // x ja y keskitävät textiä
    y = (int)(bounds().height/1.5);   
    gr.drawString(text, x, y);  // tulostaa teksti     
    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) // värinätön kuva
  { return true; }
}
