问题是页面部分只alert出了2,而定时器里面的3没有alert出来。
定时器代码如下:
public class SerialApplet extends Applet {//implements Runnable
private static int timeout=5000;
private JSObject jsObject=null;
private Timer timer;
public void init(){
setLayout(new FlowLayout()); 
try {
jsObject=JSObject.getWindow (this);
}
catch (Exception ex) {
ex.printStackTrace();
}
jsObject.eval("javascript:alert('2')");
if (timer==null) {
timer=new Timer(timeout,new ActionListener(){public void actionPerformed(ActionEvent e) {
jsObject.eval("javascript:alert('3')");
}});

}

public void start() {
timer.start();
}
}调用applet的jsp部分代码如下:
<applet codebase="." code="org.eleit.serial.SerialApplet.class" width="0" height="0" MAYSCRIPT>
</applet>