import java.applet.*;
import java.awt.*;


public class BannerText2 extends Applet implements Runnable{
	Image image;
	Graphics gr;
	String text = new String();
	int a = 0; 
	Thread th;
	int index, line, hspace, speed, sleep;
        int bgcolor, fontsize, fontstyle, fontcolor;
	Dimension d = new Dimension();
        String fontname;
 	int x, y, b;
	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();
  hspace = Integer.valueOf(getParameter("hspace")).intValue();
  bgcolor = Integer.valueOf(getParameter("bgcolor")).intValue();
  fontcolor = Integer.valueOf(getParameter("fontcolor")).intValue();
  speed = Integer.valueOf(getParameter("speed")).intValue();
  sleep = Integer.valueOf(getParameter("sleep")).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.clearRect(0, 0, d.width, d.height);
	super.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ä text
	y = d.height-5;

	b = (int)(((line-a)*fontsize)+(hspace*(line-a)));
	        
	  gr.setColor(new Color(fontcolor));
          
	for(index = 0; index < b; index++) 
	{
	gr.clearRect(0, d.height-b-fontsize-hspace, d.width, d.height);
	gr.drawString(text, x, y);
	gr.copyArea(x, y--, d.width, d.height, 0, 0); //kopioi text
	super.repaint();

	try{
	th.sleep(speed);
	   } catch(InterruptedException e){}
	
	}
	a++;
	if (a == line)
          { a = 0;
	   try{
	       th.sleep(sleep);
	      } catch(InterruptedException e){}
          }

	}
      
    }

}

