从 Flex 调用 Java Applet

发布于 2024-08-15 11:37:07 字数 201 浏览 1 评论 0原文

我正在开发 Flex 应用程序,我需要从 Flex 打开一个 Java Applet(例如单击按钮)。我特别想打开 imageJ,这是一个特定的成像程序,可以作为应用程序、小程序或集成在网页中。有没有办法从 Flex 调用它?我看过一些教程,解释了如何从 Flex 调用另一个 Java 文件中的单个函数,但我不太确定这就是我正在寻找的内容。 感谢您的回答, 干杯,

大卫

I'm working on Flex application and I need to open a Java Applet from Flex (e.g. clicking a button). In particular I'd like to open imageJ, a particular imaging program that could work as application, applet or be integrated in a web page. Is there a way to call it from Flex? I've seen a couple of tutorials that explain how to call a single function in another Java file from Flex, but I'm not so sure that it is what I'm looking for.
Thanks for your answers,
cheers,

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

锦爱 2024-08-22 11:37:07

我不知道是否有更好的方法,但如果我这样做,我会编写一个 JavaScript 函数来加载 Java 小程序(可能像 document.write(";")),然后使用 Flex 的 ExternalInterface< /a> 来调用 JavaScript。

I don't know if there's a better way, but if I was doing it, I'd write a JavaScript function that would load the Java applet (could be as simple as document.write("<object …>")), then use Flex's ExternalInterface to call that JavaScript.

泛滥成性 2024-08-22 11:37:07

在小程序中公开一个公共方法,Flex 将调用该方法。您可以通过以下方式加载小程序。这是一个示例程序,调用java方法并从java获取值,您可以根据您的需要进行更改

    <object
    id = "MyApplet"
    name = "Some name"
    classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height="0">
    <PARAM NAME = "CODE" VALUE = "com.my.applet.MyApplet.class" >
    <PARAM NAME = "CODEBASE" VALUE = "." >
    <PARAM NAME = "ARCHIVE" VALUE = "applet-client.jar" >
    <PARAM NAME = "cache_option" VALUE="No">

    <PARAM NAME = "java_version" VALUE="1.6+">
    <param name = "type" value = "application/x-java-applet;version=1.6">
    <comment>
        <embed
            name = "MyApplet"
            type = "application/x-java-applet;version=1.6" \
            CODE = "com.my.applet.MyApplet.class" \
            JAVA_CODEBASE = "." \
            ARCHIVE = "applet-client.jar"
            cache_option = "No"
            scriptable = false
            pluginspage = "http://java.sun.com/products/plugin/index.html#download"
            width="0" height="0"
        >
            <noembed>
            </noembed>
        </embed>
    </comment>

</object>

通过您的html文件中的上述内容(我不会解释所有内容),小程序将被下载并准备使用。现在,单击 Flex 应用程序上的按钮,您应该看到如下所示的内容。

var returnedStringFrom java:String=ExternalInterface.call("document.MyApplet.functionInJava",stringParam);

注意:MyApplet是上面对象声明中的名称,functionInJava是java类com.my.applet.MyApplet中的公共函数。它接受一个参数并返回一个字符串参数。 Java 程序如下所示。

package com.my.applet;

public class MyApplet{
//other methods..

public String functionInJava(String stringpm){

// your implementation 
return "SomeString";
}
}

快乐编码。

Expose a public method in your applet, which the flex would call. You could load the applet the following way. It is a sample program, to call java methods and get a value from java, you can do changes as per your need

    <object
    id = "MyApplet"
    name = "Some name"
    classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height="0">
    <PARAM NAME = "CODE" VALUE = "com.my.applet.MyApplet.class" >
    <PARAM NAME = "CODEBASE" VALUE = "." >
    <PARAM NAME = "ARCHIVE" VALUE = "applet-client.jar" >
    <PARAM NAME = "cache_option" VALUE="No">

    <PARAM NAME = "java_version" VALUE="1.6+">
    <param name = "type" value = "application/x-java-applet;version=1.6">
    <comment>
        <embed
            name = "MyApplet"
            type = "application/x-java-applet;version=1.6" \
            CODE = "com.my.applet.MyApplet.class" \
            JAVA_CODEBASE = "." \
            ARCHIVE = "applet-client.jar"
            cache_option = "No"
            scriptable = false
            pluginspage = "http://java.sun.com/products/plugin/index.html#download"
            width="0" height="0"
        >
            <noembed>
            </noembed>
        </embed>
    </comment>

</object>

With the above in your html file( I am not explaining everything) , the applet will be downloaded and ready to use. Now on click of a button on your flex app, you should have something like below.

var returnedStringFrom java:String=ExternalInterface.call("document.MyApplet.functionInJava",stringParam);

Note : MyApplet is the name in the object declaration above, the functionInJava is a public function in the the java class com.my.applet.MyApplet. It takes a parameter and returns a string parameter. The Java program will look like below.

package com.my.applet;

public class MyApplet{
//other methods..

public String functionInJava(String stringpm){

// your implementation 
return "SomeString";
}
}

Happy coding.

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