package ejb;import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class onebyone extends Applet implements Runnable, ActionListener{
String str=null;
Thread t=null;
int speed;
char chars[];
TextField a,a1;
int j=0;
Button b1;
public void init() {
Font font=new Font("TimesNewRoman",Font.PLAIN,32);
String s="123456";//getParameter("speed");//初始化得不到值,将异常。
try{
speed=(s==null)?1000:Integer.parseInt(s);
}catch(Exception e){
  System.out.println("e="+e.toString());
}
TextField a=new TextField(10);
add(a);
Button b1=new Button("Start");
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{ str=a.getText();
start();
}
}
public void paint(Graphics g){
g.drawString(str,50,200);
chars=new char[str.length()];
str.getChars(0,str.length(),chars,0);
int n;
g.setColor(Color.red);
g.setFont(new Font("TimesRoman",Font.PLAIN,32));
for(n=0;n<=j;n++)
g.drawChars(chars,n,1,100+20*n,100);
j++;
if(j>=str.length()) j=0;
}public void start(){
t=new Thread(this);
t.start();
}public void stop(){
if(t!=null){
t.stop();
t=null;
}
}public void run(){
while(true){
try{
if(str.length()==0)
break;
Thread.sleep(speed);
}
catch (InterruptedException e)
{
}
repaint();
}
}
}
我帮你改动了,你以下,但是问题很多,你在jb里一调式就回发现的。
其中你的线程有问题。有空指针异常。