moji.java
import java.awt.*;
import java.applet.Applet;
public class moji extends Applet implements Runnable {
Thread th=null;
String message,msg,cen,bef,aft;
int no,width,wait;
public void init() {
msg=getParameter("MESSAGE");
msg=" "+msg+" ";
no=msg.length();
wait=Integer.parseInt(getParameter("WAIT"));
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
Font f=new Font("TimesRoman",Font.BOLD,48);
FontMetrics fm=getFontMetrics(f);
g.setFont(f);
int width=fm.stringWidth(bef);
g.setColor(new Color(0,0,225));
g.drawString(msg,0,48);
g.setColor(new Color(255,255,255));
g.drawString(cen,width,48);
}
public void start() {
if (th==null) {
th=new Thread(this);
th.start();
}
}
public void run() {
int i;
while (true) {
try {
for (i=0;i<no-1;i++) {
bef=msg.substring(0,i);
cen=msg.substring(i,i+1);
th.sleep(100);
repaint();
}
th.sleep(wait);
}
catch(InterruptedException e){}
}
}
public void stop() {
if(th!=null) {
th.stop();
th=null;
}
}
}