从 javascript 触发小程序按钮

发布于 2024-10-13 00:57:43 字数 1419 浏览 1 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞别 2024-10-20 00:57:43

是的,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.

后eg是否自 2024-10-20 00:57:43

在小程序中创建一个方法,包装该方法中的所有代码,并从操作侦听器调用该方法 foo()。

actionPerformed(){
        foo();
    }//just illustration

现在

<applet code="com.yourcompany.MyApplet"
mayscript="true" name="myApplet" width="200" height="100">

一样,myApplet 将有 foo(); 所以来自 javascript

myApplet.foo();//it will call that method

create a method in applet wrap all code in that method and call that method foo() from action listener.

like

actionPerformed(){
        foo();
    }//just illustration

now

<applet code="com.yourcompany.MyApplet"
mayscript="true" name="myApplet" width="200" height="100">

and myApplet will have foo(); so from javascript

myApplet.foo();//it will call that method
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文