0

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

4
  • 3
    What have you tried? Commented Sep 14, 2012 at 12:49
  • @AnkurSharma he means What have you tried? Commented Sep 14, 2012 at 12:49
  • I have not yet started this idea. I just wanted to make sure if it is possible or not! Commented Sep 14, 2012 at 12:51
  • It's possible, but it's somewhat tricky to do in a way that doesn't easily allow for people to upload whichever score they want, without actually playing the game. Commented Sep 14, 2012 at 12:53

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Please don't post links as answers. Give a brief description instead and give the link as reference
1
  1. i think you should save all the highscores in database

  2. use that scores using php or other language

5 Comments

is there a special class in java to save data to mySQL? sorry i am a newb
@AnkurSharma jdbc will help u ..I am a php developer use google for more information ,This can help u tutorial
@Lokesh It's a very bad idea to connect directly to your database in a Java Applet. If you can do this, it means that anybody with sufficient (not much is required) technical knowledge could connect and do some real damage to your database. You database should be behind a firewall and not accessible to the outside world.
@Kibbee how can i make it behind a firewall?
@Kibbee i am not a java developer...i have suggested a logic how to perform this
0

Your applet is allowed to call URLs on originating server. This can be used to save higscores.

2 Comments

And how would you then push the high-scores to the front-end?
I would pull them from some URL I'm allowed to call from my applet. You can not push data from webserver to browser, and I would not allow any sockets to be opened to my backend from outside

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.