如何在一个Click事件载入我的Java小程序? [英] How do I load a my Java Applet on a Click event?

查看:225
本文介绍了如何在一个Click事件载入我的Java小程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DIV ,其中我打开一个Java小程序,但Java的新版本是给一个无符号的证书错误:

我想知道如果我可以限制我的Java小程序的加载( DeployJava.RunApplet ),而页面加载当前实例化,只有当负荷用户点击在3D的查看的按钮?

小程序加载code:

 < D​​IV ID =appletContainer=服务器的风格=WIDTH:(document.body.clientWidth  -  270);身高:300的ClientIDMode =静态&GT ;
    <脚本类型=文/ JavaScript的>
        变种showCI = 0;
        如果(的document.getElementById(hdnHas3D)值==1&安培;。&放大器;!isAppleMobile()){
            VAR J3DStyleID =的document.getElementById(hdn3DStyleID)值。
            变量code =com.wirefusion.player.AppletPlayer;
            VAR archiveList中=一些achive清单;
            VAR WIDTH = document.body.clientWidth - 270;
            VAR HEIGHT = 300;            VAR属性= {
                ID:appletContainerX
                名称:J3DStyleID,
                code:code,
                codeBase类:,。
                宽度:宽度,
                身高:身高,
                MAYSCRIPT:真
            };
            VAR参数= {
                progressFunc:handleAppletProgress
                档案:archiveList中,
                java_arguments:-Xmx200m
                REGID:6050-25,
                resourcefolder:/ RichContent / 3D_Vehicles / J3D /车/+ J3DStyleID +/,
                preloadfile:J3DStyleID +的.jar
                environmentType:网站,
                environmentWidth:宽度,
                environmentHeight:身高,
                groupsXMLFile:../../Resources/groups.xml
                vehicleXMLFile:J3DStyleID +的.xml
            };
            VAR的版本='1.6.0_20';
            如果(deployJava.versionCheck(版++)){
                docWriteWrapper(函数(){
                    deployJava.runApplet(属性,参数,版本);
                });
            }其他{
                如果(的document.getElementById(iframeContainer)。的style.display!=无){
                    警报(无法加载交互模式);
                    showCI = 1;                }
            }
        }
    < / SCRIPT>
< / DIV>


解决方案

不包括常规<小程序> (或<对象>在HTML )的标签。相反按照有关如何做到动态地将其添加到您的网页,使用JavaScript本教程

HTML 4

 函数loadApplet(code,codeBase类,宽度,高度,ALT){
    变种占位=的document.getElementById('占位符');
    如果(window.opera){
        placeholder.innerHTML ='<小程序code =+ code +'codeBase类=+ codeBase的+'WIDTH =+宽+'HEIGHT =+高度+ 'ALT =+ ALT +'>< /小程序>';
    }其他{
        VAR一个=使用document.createElement('小程序');
        a.setAttribute('code',code);
        a.setAttribute('codeBase的',codeBase类);
        a.setAttribute('宽',宽度);
        a.setAttribute(高度,身高);
        a.setAttribute(ALT,ALT);
        placeholder.appendChild(一);
    }
}

HTML 5

 函数loadApplet(code,codeBase类,宽度,高度,ALT){
    变种占位=的document.getElementById('占位符');
    VAR一个=使用document.createElement('对象');
    a.setAttribute('型','应用程序/ x-j​​ava的小程序');
    a.setAttribute('宽',宽度);
    a.setAttribute(高度,身高);
    a.setAttribute(ALT,ALT);    变量codeParam =使用document.createElement('参数');
    codeParam.setAttribute('名','code');
    codeParam.setAttribute('价值',code);
    a.appendChild(codeParam);    变量codebaseParam =使用document.createElement('参数');
    codebaseParam.setAttribute('名','codeBase的');
    codebaseParam.setAttribute('价值',codeBase类);
    a.appendChild(codebaseParam);    placeholder.appendChild(一);
}

在你的HTML创建占位符 DIV ,即要它被装入,并链接到加载的小程序。您将需要自定义负载链接的值到你的小程序的值。

 < D​​IV ID =占位符>< / DIV>
<输入类型=按钮值=加载小程序的onclick =loadApplet('TestApplet.class','200','300','演示程序'。')/>

链接的教程将介绍更多有关如何使pretty。上面的code是只是单纯的概念。


更新,因为问题的修改

您code似乎加载使用JavaScript已经是小程序。问题是,当用户点击在3D的查看的按钮,在脚本被尽快在页面加载和不运行。

要prevent立即运行,你可以用装载机code在被调用函数 loadApplet 。因此,在伪code解释:

 函数loadApplet(){
    //您现有的小程序加载code
}

因此​​,使用您的源代码包含code,我有一个功能,这将prevent时加载你的页面运行它包好。

 < D​​IV ID =appletContainer=服务器的风格=WIDTH:(document.body.clientWidth  -  270);身高:300的ClientIDMode =静态&GT ;
    <脚本类型=文/ JavaScript的>
        //包装你code。与一个叫loadApplet功能
        功能loadApplet(){
            //你的小应用程序加载code:
            变种showCI = 0;
            如果(的document.getElementById(hdnHas3D)值==1&安培;。&放大器;!isAppleMobile()){
                VAR J3DStyleID =的document.getElementById(hdn3DStyleID)值。
                变量code =com.wirefusion.player.AppletPlayer;
                VAR archiveList中=一些achive清单;
                VAR WIDTH = document.body.clientWidth - 270;
                VAR HEIGHT = 300;                VAR属性= {
                    ID:appletContainerX
                    名称:J3DStyleID,
                    code:code,
                    codeBase类:,。
                    宽度:宽度,
                    身高:身高,
                    MAYSCRIPT:真
                };
                VAR参数= {
                    progressFunc:handleAppletProgress
                    档案:archiveList中,
                    java_arguments:-Xmx200m
                    REGID:6050-25,
                    resourcefolder:/ RichContent / 3D_Vehicles / J3D /车/+ J3DStyleID +/,
                    preloadfile:J3DStyleID +的.jar
                    environmentType:网站,
                    environmentWidth:宽度,
                    environmentHeight:身高,
                    groupsXMLFile:../../Resources/groups.xml
                    vehicleXMLFile:J3DStyleID +的.xml
                };
                VAR的版本='1.6.0_20';
                如果(deployJava.versionCheck(版++)){
                    docWriteWrapper(函数(){
                        deployJava.runApplet(属性,参数,版本);
                    });
                }其他{
                    如果(的document.getElementById(iframeContainer)。的style.display!=无){
                        警报(无法加载交互模式);
                        showCI = 1;                    }
                }
            }        }
    < / SCRIPT>
< / DIV>

然后在3D您的查看的元素,你必须添加的onclick 属性调用 loadApplet()的功能。例如:

 <输入类型=按钮值=显示在3D的onclick =loadApplet()/>

请注意:这可能是因为在3D您的查看的按钮已经有一个的onclick 属性有线到将您的applet到一个函数的情况下看来,在这种情况下,你仍然想给你的加载功能后,才能调用。我已经使用 showApplet()为例,这是最有可能不同的你。

 <输入类型=按钮值=显示在3D的onclick =loadApplet(); showApplet(); />

如果您提供在3D code为您的显示的按钮,我可以更好地帮助你在这里。

I have a div where I load a Java Applet, but the new version of Java is giving an unsigned certificate error:

I would like to know if I can restrict the loading of my Java Applet (DeployJava.RunApplet), currently instantiated while the page is loaded, to only load when user clicks the View in 3D button?

Applet Loading Code:

<div id="appletContainer" runat="server" style="width:(document.body.clientWidth - 270);height:300" clientidmode="Static">
    <script type="text/javascript">
        var showCI = 0;                                        
        if (document.getElementById("hdnHas3D").value == "1" && !isAppleMobile()) {
            var J3DStyleID = document.getElementById("hdn3DStyleID").value;
            var code = "com.wirefusion.player.AppletPlayer";
            var archiveList = "Some achive List";                                         
            var width = document.body.clientWidth - 270;
            var height = 300; 

            var attributes = {
                id: "appletContainerX",
                name: J3DStyleID,
                code: code,
                codebase: ".",
                width: width,
                height: height,
                mayscript: "true"
            };
            var parameters = {
                progressFunc: "handleAppletProgress",
                archive: archiveList,
                java_arguments: "-Xmx200m",
                regid: "6050-25",                                                
                resourcefolder: "/RichContent/3D_Vehicles/J3D/Vehicles/" + J3DStyleID + "/",
                preloadfile: J3DStyleID + ".jar",
                environmentType: "WEBSITE",
                environmentWidth: width,
                environmentHeight: height,
                groupsXMLFile: "../../Resources/groups.xml",
                vehicleXMLFile: J3DStyleID + ".xml"
            };
            var version = '1.6.0_20'; 
            if (deployJava.versionCheck(version + '+')) {
                docWriteWrapper(function () {
                    deployJava.runApplet(attributes, parameters, version);
                });                                               
            } else {
                if (document.getElementById("iframeContainer").style.display != "none") {
                    alert("Unable to load Interactive mode");
                    showCI = 1;

                }
            }
        }
    </script>
</div>

解决方案

Don't include the regular <applet> (or <object>) tag in your HTML. Instead follow this tutorial on how to do dynamically add it to your page, using JavaScript.

HTML 4

function loadApplet(code,codebase,width,height,alt){
    var placeholder=document.getElementById('placeholder');
    if(window.opera){
        placeholder.innerHTML='<applet code="'+code+'" codebase="'+codebase+'" width="'+width+'" height="'+height+'" alt="'+alt+'"></applet>';
    }else{
        var a=document.createElement('applet');
        a.setAttribute('code',code);
        a.setAttribute('codebase',codebase);
        a.setAttribute('width',width);
        a.setAttribute('height',height);
        a.setAttribute('alt',alt);
        placeholder.appendChild(a);
    }
}

HTML 5

function loadApplet(code,codebase,width,height,alt){
    var placeholder=document.getElementById('placeholder');
    var a = document.createElement('object');
    a.setAttribute('type','application/x-java-applet');
    a.setAttribute('width',width);
    a.setAttribute('height',height);
    a.setAttribute('alt',alt);

    var codeParam = document.createElement('param');
    codeParam.setAttribute('name','code');
    codeParam.setAttribute('value',code);
    a.appendChild(codeParam);

    var codebaseParam = document.createElement('param');
    codebaseParam.setAttribute('name','codebase');
    codebaseParam.setAttribute('value',codebase);
    a.appendChild(codebaseParam);

    placeholder.appendChild(a);
}

In your HTML create a placeholder DIV, i.e. where you want to it to be loaded into, and a link to load your applet. You will need to customise the values in the load link to your values of the Applet.

<div id="placeholder"></div>
<input type="button" value="Load Applet" onclick="loadApplet('TestApplet.class','.','200','300','demo applet')" />

The linked tutorial explains more about how to make it pretty. The code above is just simply the concept.


Update since modification of question

Your code appears to load the applet using JavaScript already. The problem is the script is being run as soon as the page is loaded and not when the user clicks on the View in 3D button.

To prevent it running immediately, you can wrap the loader code in a function called loadApplet. So explained in pseudo code:

function loadApplet() {
    // Your existing applet loading code
}

So using your included source code, I have wrapped it with a function, which will prevent it running when your page is loaded.

<div id="appletContainer" runat="server" style="width:(document.body.clientWidth - 270);height:300" clientidmode="Static">
    <script type="text/javascript">
        // Wrap your code with a function called loadApplet
        function loadApplet() {
            // Your applet loading code:
            var showCI = 0;                                        
            if (document.getElementById("hdnHas3D").value == "1" && !isAppleMobile()) {
                var J3DStyleID = document.getElementById("hdn3DStyleID").value;
                var code = "com.wirefusion.player.AppletPlayer";
                var archiveList = "Some achive List";                                         
                var width = document.body.clientWidth - 270;
                var height = 300; 

                var attributes = {
                    id: "appletContainerX",
                    name: J3DStyleID,
                    code: code,
                    codebase: ".",
                    width: width,
                    height: height,
                    mayscript: "true"
                };
                var parameters = {
                    progressFunc: "handleAppletProgress",
                    archive: archiveList,
                    java_arguments: "-Xmx200m",
                    regid: "6050-25",                                                
                    resourcefolder: "/RichContent/3D_Vehicles/J3D/Vehicles/" + J3DStyleID + "/",
                    preloadfile: J3DStyleID + ".jar",
                    environmentType: "WEBSITE",
                    environmentWidth: width,
                    environmentHeight: height,
                    groupsXMLFile: "../../Resources/groups.xml",
                    vehicleXMLFile: J3DStyleID + ".xml"
                };
                var version = '1.6.0_20'; 
                if (deployJava.versionCheck(version + '+')) {
                    docWriteWrapper(function () {
                        deployJava.runApplet(attributes, parameters, version);
                    });                                               
                } else {
                    if (document.getElementById("iframeContainer").style.display != "none") {
                        alert("Unable to load Interactive mode");
                        showCI = 1;

                    }
                }
            }

        }
    </script>
</div>

Then to your View in 3D element you must add an onclick attribute calling the loadApplet() function. For example:

<input type="button" value="Show in 3D" onclick="loadApplet()" />

Note: It may be the case that your View in 3D button already has an onclick attribute wired to a function that brings your applet into view, in which case you would still want this to be called after your load function. I have used showApplet() as an example, this is most likely different for you.

<input type="button" value="Show in 3D" onclick="loadApplet(); showApplet();" />

If you provide the code for your Show in 3D button, I can better assist you here.

这篇关于如何在一个Click事件载入我的Java小程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆