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?


  • 写回答

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
   "myJavscriptFunction", null);
             // if you wish to pass an argument to the javascript function,
             // do the following
             String myString = "World!";
             final Object[] args = { myString };  
   "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/" MAYSCRIPT=true
       No JDK 1.3 support for APPLET!!

    Now the javascript function in your HTML/PHP file

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


    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 关于cpci总线的几个问题,有点迷糊
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做
  • ¥15 通关usb3.0.push文件,导致usb频繁断连
  • ¥15 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化
  • ¥15 搭建QEMU环境运行OP-TEE出现错误