从 javascript 触发小程序按钮
我想使用 javascript 单击普通 html 按钮来触发小程序按钮
public class appletToWrite extends Applet{
Button write;
static String msPath;
static String msData;
public appletToWrite()
{
this.write = new Button("Save");
}
public static void initializeData(String asPath, String asData){
msPath = asPath;
msData = asData;
}
public void init() {
add(this.write, "Center");
this.write.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent paramActionEvent) {
foo();
}
}); }
public void foo(){
new appletToWrite.WriteText();
}
public class WriteText {
WriteText() {
try {
String str2 = "D:\\Documents and Settings\\varun.aggarwal\\Desktop\\sample\\wow.htm";
File localFile = new File(str2);
localFile.createNewFile();
BufferedWriter localBufferedWriter = new BufferedWriter(new FileWriter(localFile, true));
String str1="helllllllo";
localBufferedWriter.write(str1);
localBufferedWriter.close();
JOptionPane.showMessageDialog(null, "File Successfully Saved!!! ");
}
catch (Exception localException) {
JOptionPane.showMessageDialog(null, localException.getMessage());
}
}
}
}
这可能吗???
这是与权限相关的事情,因为我发现文件 IO 权限仅在我单击小程序按钮时可用,而不是在我单击 html 按钮并调用小程序方法 foo 时可用
i want to trigger an applet button on click of a normal html button using javascript
public class appletToWrite extends Applet{
Button write;
static String msPath;
static String msData;
public appletToWrite()
{
this.write = new Button("Save");
}
public static void initializeData(String asPath, String asData){
msPath = asPath;
msData = asData;
}
public void init() {
add(this.write, "Center");
this.write.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent paramActionEvent) {
foo();
}
}); }
public void foo(){
new appletToWrite.WriteText();
}
public class WriteText {
WriteText() {
try {
String str2 = "D:\\Documents and Settings\\varun.aggarwal\\Desktop\\sample\\wow.htm";
File localFile = new File(str2);
localFile.createNewFile();
BufferedWriter localBufferedWriter = new BufferedWriter(new FileWriter(localFile, true));
String str1="helllllllo";
localBufferedWriter.write(str1);
localBufferedWriter.close();
JOptionPane.showMessageDialog(null, "File Successfully Saved!!! ");
}
catch (Exception localException) {
JOptionPane.showMessageDialog(null, localException.getMessage());
}
}
}
}
is it possible???
this is something related to permissions as i found that file IO permissions are availabale only when i click on applet button and not when i click html button and call the applet method foo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,JavaScript 到 Applet 以及 Applet 到 Javascript 都是可能的。
查看此页面的代码示例:Java - Javascript 交互。
Yes, it is possible, both JavaScript to Applet and Applet to Javascript.
Take a look at this page for code samples: Java - Javascript interaction.
在小程序中创建一个方法,包装该方法中的所有代码,并从操作侦听器调用该方法 foo()。
像
现在
一样,myApplet 将有
foo();
所以来自 javascriptcreate a method in applet wrap all code in that method and call that method foo() from action listener.
like
now
and myApplet will have
foo();
so from javascript