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 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥20 关于#stm32#的问题:STM32串口发送问题,偶校验(even),发送5A 41 FB 20.烧录程序后发现串口助手读到的是5A 41 7B A0
  • ¥15 C++map释放不掉
  • ¥15 Mabatis查询数据
  • ¥15 想知道lingo目标函数中求和公式上标是变量情况如何求解
  • ¥15 关于E22-400T22S的LORA模块的通信问题
  • ¥15 求用二阶有源低通滤波将3khz方波转为正弦波的电路
  • ¥15 大气压等离子体射流数值模拟
  • ¥15 单片机AD原理图52单片机
  • ¥15 用Matlab神经网络工具箱得到多个神经网络模型,有没有人知道怎么把多个神经网络结合成一个新的神经网络,实现对不同来源的数据都能用这个新的神经网络高精度预测的目的(相关搜索:数据集)