// 逐字显示 zzxs.java 2003.8.28.
import java.awt.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class zzxs extends java.applet.Applet implements Runnable {
Thread runThread;
String s = "欢迎浏览 计算机教学园地 !";
int s_length = s.length();
int x_character = 0;
Font wordFont=new Font("宋体" , Font.BOLD , 40);
public void start() {
if(runThread==null){
runThread = new Thread(this);
runThread.start();
}
}
public void stop() {
if(runThread!=null){
runThread.stop();
runThread=null;
}
}
public void run() {
while(true) {
if (x_character++>s_length)
x_character = 0;
repaint ();
try {
Thread.sleep(555);
} catch (InterruptedException e) {}
}
}
public void paint (Graphics g) { setBackground(Color.green);
g.setFont (wordFont);
g.setColor (Color.red);
g.drawString (s.substring(0,x_character), 8, 50);
}
public boolean handleEvent(Event e) {
// 事件处理
switch (e.id) {
case Event.WINDOW_DESTROY:
System.exit(0);
return true;
default:
return false;
}
}
public static void main(String args[]){ // Application程序入口
Frame f = new Frame("逐字显示程序");
// 创建Application程序框架
zzxs drawTest = new zzxs();
drawTest.init();
drawTest.start();
f.add("Center", drawTest);
f.resize(400, 100);
f.show();
}
}