import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Scroll extends Applet implements Runnable{
String text;
int xpos,realLength,realHeight,width,height,velocity;
boolean threadSuspended=false;
Font font;
Color fgcolor,bgcolor;
Thread mover=null;
Image offScreen;
Graphics osGraphics;
public Scroll(){
xpos=400;
width=400;
height=40;
velocity=5;
threadSuspended=false;
}
public void init(){
String str=getParameter("text");
text=(str!=null)?str:"No text";
int fontSize=str==null?24:Integer.parseInt(str);
str=getParameter("fontstyle");
int fontStyle=Font.PLAIN;
if(str!=null)
{str.toUpperCase();
if(str.compareTo("ITALIC")==0)
fontStyle=Font.ITALIC;
else if(str.compareTo("BOLD")==0)
fontStyle=Font.BOLD;
}
font=new Font("Serif",fontStyle,fontSize);
str=getParameter("velocity");
velocity=str==null?5:Integer.parseInt(str);
str=getParameter("fgcolor");
int c=str==null?0:Integer.parseInt(str,16);
fgcolor=new Color(c);
str=getParameter("bgcolor");
c=str==null?0xffffff:Integer.parseInt(str,16);
bgcolor=new Color(c);
width=getSize().width;
height=getSize().height;
offScreen=createImage(width,height);
}
private void paintText(Graphics g){
g.setColor(bgcolor);
g.fillRect(0,0,width,height);
g.clipRect(0,0,width,height);
g.setFont(font);
g.setColor(fgcolor);
FontMetrics fontmetrics=g.getFontMetrics();
realLength=fontmetrics.stringWidth(text);
realHeight=fontmetrics.getHeight();
g.drawString(text,xpos,(height+realHeight)/2);
}
public void paint(Graphics g){
paintText(offScreen.getGraphics());
g.drawImage(offScreen,0,0,null);
}
public void start(){
if(mover==null){
mover=new Thread(this);
mover.start();
}
}
public void stop(){
mover=null;
}
private void setcoord(){
xpos=xpos-velocity;
if(xpos<-realLength)xpos=width;
}
public void run(){
while(mover!=null)
{ try{
Thread.currentThread().sleep(100L);
}catch(InterruptedException _ex){}
setcoord();
repaint();
}
}
public void update(Graphics e){
paint(e);
}
public boolean handleEvent(Event event){
if(event.id==Event.MOUSE_DOWN){
if(threadSuspended)
/*
mover.resume();
else
mover.suspend();
*/
threadSuspended=!threadSuspended;
}
return true;
}
}