import java.applet.*;
import java.awt.*;


public class RBannerText extends Applet implements Runnable{
	Image image;
	Graphics gr;
	String text = new String();
	int a = 0; 
	Thread th;
	int index, line;
        int fontcolor, bgcolor, fontsize, fontstyle;
	Dimension d = new Dimension();
        String fontname;
 	int x;
	Font font;
	
public void init()
 {
  fontsize = Integer.valueOf(getParameter("fontsize")).intValue();
  fontstyle = Integer.valueOf(getParameter("fontstyle")).intValue();
  fontname = getParameter("fontname");
  line = Integer.valueOf(getParameter("line")).intValue();
  fontcolor = Integer.valueOf(getParameter("fontcolor")).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){
	gr.setColor(getBackground()); // tyhjä kuva          
    	gr.fillRect(0, 0, d.width, d.height);

	repaint();
	th = new Thread(this);
	th.start();
			
		    }	
	           }

public void stop(){
        if(th != null){

	th.stop();
	th = null;
		    }
	          }


public void update(Graphics g){
      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; }

public void run(){
				
     while(true){	
	
	text = getParameter("text"+a);

	x = (d.width - getFontMetrics(font).stringWidth(text))/2; 
           //keskitä x
			
	gr.setColor(new Color(fontcolor));
	for(index = 0; index < text.length()+1; index++)// tulostaa text
	{
	gr.drawString(text.substring(0,index), x, 26);
	repaint();
	try{
		th.sleep(50);
	   } catch(InterruptedException e) {}
		}

		a++; // vaihtaa text
		if (a == line) a = 0;

			
	try{
	th.sleep(2000);
	   } catch(InterruptedException e){}
			
	for(index = 0; index < fontsize + 2; index++) 
	{
	gr.copyArea(0, 1, d.width, d.height, 0, -1); //kopioi text
	repaint();

	try{
	th.sleep(50);
	   } catch(InterruptedException e){}
	}
      }
    }

}

