doukun0888 2012-09-14 12:46
浏览 41
已采纳

是否有可能从Java Applet获取数据到PHP或MySQL?

I want to create a website with a game in applet form. I want to use the highscores that people get in the game to show up on a leaderboard on the website? How is this achievable?

Thanks

  • 写回答

3条回答 默认 最新

  • dongshendie8849 2012-09-14 12:49
    关注

    That can be done with JSObject, basically you pass information between Javascript and Java.

    Example based on the documentation .

    Let's say this is your Java Applet, the netscape.javascript.* library is used to call the Plugin container of your browser (the window your Java Applet runs in) to pass information to, or from it. This is example is from the documentation, you can change the version to your preferred JDK version to whatever version you use.

    import netscape.javascript.*;
    import java.applet.*;
    import java.awt.*;
    class MyApplet extends Applet {
         public void init() {
    
             // requesting the JSObject
             JSObject win = JSObject.getWindow(this);
    
             // here you call a javascript function
             win.call("myJavscriptFunction", null);
    
             // if you wish to pass an argument to the javascript function,
             // do the following
             String myString = "World!";
             final Object[] args = { myString };  
             win.call("myJavascriptFunction2()", args);
         }
    }
    

    I will use the EMBED tag as an example, but the OBJECT (IE etc) tag can used also (see documentation in the link on top). The most important property you should not forget, is enabling MAYSCRIPT=true

    <EMBED type="application/x-java-applet;version=1.3" width="200"
       height="200" align="baseline" code="XYZApp.class"
       codebase="html/" model="models/HyaluronicAcid.xyz" MAYSCRIPT=true
       pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html">
    <NOEMBED>
       No JDK 1.3 support for APPLET!!
    </NOEMBED>
    </EMBED>
    

    Now the javascript function in your HTML/PHP file

    <script text="text/javascript">
      function myJavascriptFunction() {
        alert("Hello!");
      }
    
      /**
       * with argument
       */
      function myJavascriptFunction2(myString) {
         alert("Hello "+myString);
         // will produce "Hello World!";
      }
    </script>
    

    reference: java.sun.com/products/plugin/1.3/docs/jsobject

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧