我正在尝试为 firebug 开发一个扩展。我想在这个扩展中调用一个 java 方法,但是里面没有 html,所以我不能使用 applet-html 解决方案。
这是我的java小程序:
import java.applet.Applet;
import javax.swing.JOptionPane;
public class MyApplet extends Applet {
public void init() {
super.init();
System.out.println("init something");
}
public String jsCall(String hello) {
System.out.println("this method is called by a js function and say :"
+ hello);
Thread t = new Thread(new Runnable(){
public void run(){
JOptionPane jop1 = new JOptionPane();
jop1.showMessageDialog(null, "Message informatif", "Information", JOptionPane.INFORMATION_MESSAGE);
}
});
t.start();
return "lala";
}
}
我试试这个:
var applet = document.createElement("applet");
applet.setAttribute("code","file:///home/dacostam/z_test/firebug-extension-examples-0bdcf15/helloamd@janodvarko.cz/chrome/content/MyApplet.class");
applet.setAttribute("id","javaToJavascriptApplet");
applet.setAttribute("mayscript","true");
applet.jsCall("HelloWorld"); //jsCall not a function
还有这个:
var dom = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
dom.appendChild(applet);
dom.javaToJavascriptApplet.jsCall("HelloWorld"); //jsCall not a function
该文档与往常不同,其中没有正文或 html。
有没有其他方法可以在 javascript 中调用 java 而不是 applet-html 解决方案?或者有没有办法用这种方法来做呢?
如果您需要更多信息,我在这里。
谢谢。
编辑:
向您解释程序的作用会很长,请记住它不可避免地在 java 中,我只需要调用一个带有参数字符串并返回字符串或最终为 void 的方法。
编辑2:
对不起,我没有想到,java需要在客户端运行。