日期:2014-05-16  浏览次数:20310 次

在applet调用js时出现错误(已解决)
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JApplet;
import netscape.javascript.JSObject;

public class AppletTest extends JApplet{
    /**
*
*/
private static final long serialVersionUID = 2171316410722327511L;
public AppletTest() {
        System.out.println("AppletTest============1");
    }
    public void init() {
        System.out.println("AppletTest============2");
        new Thread(){
            public void run(){
                try{
                    while(true){
                        Thread.sleep(1000);
                        System.out.println("init=======================" + getTime());
                    }           
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }.start();
        String parame = "{\"success\":true,\"info\":\"加载完成\"}";
        System.out.println("加载完成=======================" + getTime());
        runJS("initFinish", parame); //调用客户端js方法的
    }
    /**
     *
     * @param json 传入的字符串数据
     * @param fun 回调的函数
     */
    public void myMethod(final String json, final String fun){
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                new Thread(){ // 另起线程,避免客户端等待applet返回数据卡死
                    public void run(){
                        try{
                            System.out.println("1Thread=======================" + getTime());
                            String parame = "{\"success\":true,\"info\":\"执行完毕\"}";