views:

614

answers:

2

I've built a small applet and I have all the .java class files. How can I now compile/build it so I can use it in an <applet> tag? An eclipse based method would be best.

Also, I'm using some images in the applet.

1) Do I need to upload these images to my website

2) Right now I point to them using my local path e.g C:\java\project\images but its all kept in 1 class so i can change this string easily if I want. What should I change it to so it'll work in a web browser?

3) Do I need to upload all the .class files?

+3  A: 

You'll need to upload everything, or nobody will be able to download them! Package everything into a Jar, and make your applet run from that. There are good docs for rolling out applets all over the net.

With your images you have two choices. Include them in the jar, or make them available over HTTP at runtime. Either way you'll have to change your code from loading them off the C: drive! Include them in the jar is probably best - you'll be downloading them anyways and it'll be better done with the jar in the one transaction.

Eclipse can be made to do it all automatically for you with Ant, but I'd do it manually at first to be sure you understand what's going on. You'll need to build a jar for your applet and an HTML page to launch it from, and then upload them both to your webserver.

banjollity
+2  A: 

You definetely need to bundle your applet and images in jar files.

If the images are very large and if all of them may not always be needed in the Applet, then deploy them as single files on your webserver, otherwise package them in the jar with your Applet.

If you package the images with the Applet in it's jar then you should load them from the classpath, using Class.getResourceAsStream(...)

If they are available as individual image files, then load them from there URL.

Parag