从javascript调用JApplet函数不是函数
Call JApplet function from javascript is not a function
我试图从javascript调用一个JApplet函数,但它不起作用。
这是我的小程序的代码:
public class Main extends JApplet implements ActionListener {
private static final long serialVersionUID = 1L;
private JTextArea m_textArea;
private JButton m_button;
public String mypublicvariable = "foo";
public Main() {
this.setLayout(null);
m_textArea = new JTextArea();
m_textArea.setBounds(25, 25, 200, 100);
m_textArea.setText("some value");
getContentPane().add(m_textArea);
m_button = new JButton("crypt");
m_button.setBounds(25, 150, 100, 20);
m_button.addActionListener(this);
getContentPane().add(m_button);
}
public static void main(String[] args) {
new Main();
}
@Override
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource().equals(m_button)) {
m_textArea.setText("worked");
}
}
public void doSomething() {
m_textArea.setText("sdlkjfdöjdlkjfsfsyfhudjfdsfj");
}
}
这是我的HTML代码:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<applet name="TestApplet" id="TestApplet" code="main.Main" archive="test.jar" width="500" height="500" />
<script>
console.warn(document.TestApplet.mypublicvariable);
document.TestApplet.doSomething();
</script>
</body>
</html>
我既得不到公共变量的值(未定义),也不能调用公共函数(document.TestApplet.doSomething不是函数)。为了澄清,我将Main类的整个项目导出为一个jar文件,并将其命名为test.jar。
scriptable
标志。
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 如何在JavaScript中将字符串转换为函数引用
- 用嵌套函数和默认函数定义函数
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- JQuery合并了keyup和focusout两个函数
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- jquery点击函数select&取消选择
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- Node.js v6.2.0类扩展不是函数错误
- 比较从函数和生成的日期对象
- jQuery中是否内置了任何字符串格式化函数
- 从javascript调用JApplet函数不是函数