简体   繁体   中英

Java applet using JAR?

I currently have a in-development Java Game.

It runs from a .jar, with all the image files inside. The .jar creates and accesses files in the working directory.

I was wondering if there was a simple way to put this on a webpage as a Java Applet. I currently have Applet code in the Game, but all it does is calls the normal main method to create JFrames and run the game.

I need a simple way to run this on clients from a webpage, prefferably an applet? Is there one?

Please note, I didn't actually make this as an Applet at first. It's currently a .jar, with a .bat to run it. My "Applet" class is this simple...

package explorer.applet;


import java.applet.Applet;

import explorer.boot.Startup;

@SuppressWarnings("serial")
public class ExplorerApplet extends Applet{

public void init()
{
    Startup.wp = true;
    Startup.main(null);
}

}

I was wondering if there was a simple way to put this on a webpage..

Sure. Launch a JFrame direct from a link using Java Web Start .

..as a Java Applet.

Why? Applets are harder to deploy and maintain, and provide a less satisfactory experience to the end user.


Note that the fundamental problem is the same either way. 'How to access an application resource?'

Such resource access would be by URL . There are these 2 primary alternatives:

  1. Add the resource to the Jar and use Class.getResource("/path/to/the.resource")
  2. Put the resource 'loose' on the home server, and form the URL relative to the code base or document base of the applet, or the code base of the JNLP (the file used to configure a JWS launch).

The .jar creates and accesses files in the working directory.

About 4MB, and they store the game information. (It's a 2D world game.)
They also have to be client side, and in the folder that the "jar" runs from.

That is too large for any of the sand-boxed techniques I had in mind, but since it is 'static' 1 resources - they can be added to a Jar which is on the run-time class-path and thereby will be 'downloaded and made available to the app.'.

Access the resources as described above.

  1. By 'static' I simply mean 'do not need to be edited or changed by the user or app.', as opposed to something like 'high scores' which must logically be written by the app. on game exit. It is still possible to update the maps, all you need to do is provide the updated Jar and Java will do the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM