Embedding Java Applet into .html file

前端 未结 2 880
闹比i
闹比i 2020-11-27 06:29

I am having trouble embedding my applet into a webpage. I don\'t think I\'m doing it correctly.

* I have my html file in the same directory as my .class fil

相关标签:
2条回答
  • 2020-11-27 06:46

    Making applets work across a wide range of browsers is surprisingly hard. The tags weren't properly standardized in the early days, so Internet Explorer and Mozilla went separate directions.

    Sun developed a generic JavaScript to handle all the specific browser quirks, so that you don't have to worry about browser compatibility.

    Add this to your <head> section:

    <script src="//www.java.com/js/deployJava.js"></script>
    

    And this to <body> section:

    <script>
        var attributes = {codebase: 'http://my.url/my/path/to/codebase',
                          code: 'my.main.Applet.class',
                          archive: 'my-archive.jar',
                          width: '800', 
                          height: '600'};
        var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
        var version = '1.5'; // JDK version
        deployJava.runApplet(attributes, parameters, version);
    </script>
    

    See Java™ Rich Internet Applications Deployment Advice for a detailed explanation of the script and all the possible options.

    0 讨论(0)
  • 2020-11-27 07:02

    I agree that deployJava.js is preferred approach nowadays.

    Then follow several old multi-browser tricks for historical completeness.

    https://www.ailis.de/~k/archives/63-How-to-use-Java-applets-in-modern-browsers.html:

    <object id="testapplet-object" 
            classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
            width="256" height="256"
            codebase="http://java.sun.com/update/1.6.0/jinstall-6u30-windows-i586.cab#Version=1,6,0,0">
      <param name="archive" value="mytest.jar" />
      <param name="code" value="my.package.MyClass" />
      <param name="myParam" value="My Param Value" />
      <embed id="testapplet-embed"
             type="application/x-java-applet;version=1.6"
             width="256" height="256" 
             archive="mytest.jar"
             code="my.package.MyClass" 
             pluginspage="http://java.com/download/"
             myParam="My Param Value" />
      </embed>
    </object>
    

    http://joliclic.free.fr/html/object-tag/en/object-java.html (has several variations):

    <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
            width="150" height="80">
      <param name="codebase" value="data" >
      <param name="code" value="JitterText">
      <param name="BGCOLOR" value="000000">
      <param name="TEXTCOLOR" value="FF0000">
      <param name="TEXT" value="OJITesting!">
      <param name="SPEED" value="250">
      <param name="RANDOMCOLOR" value="1">
    
      <!--[if gte IE 7]> <!-->
      <object classid="java:JitterText.class"
              codebase="data"
              type="application/x-java-applet"
              width="150" height="80">
        <param name="code" value="JitterText">
        <!-- Safari browser needs the following param -->
        <param name="JAVA_CODEBASE" value="data">
        <param name="BGCOLOR" value="000000">
        <param name="TEXTCOLOR" value="FF0000">
        <param name="TEXT" value="OJITesting!">
        <param name="SPEED" value="250">
        <param name="RANDOMCOLOR" value="1">
        alt : <a href="data/JitterText.class">JitterText.class</a>
      </object>
      <!--<![endif]-->
      <!--[if lt IE 7]>
        alt : <a href="data/JitterText.class">JitterText.class</a>
      <![endif]-->
    
    </object>
    
    0 讨论(0)
提交回复
热议问题