patrickaaronmoore
patrickaaronmoore

Reputation: 11

Trouble running an applet made in Eclipse in a browser

I have made a Java applet game in Eclipse which has many classes and media associated with it. I have now been trying to finally test the game in a browser but I am having a hell of a hard time getting it to work.

I have exported a .jar file (a non-runnable, could that be a problem?) and tried many different ways of loading the applet. I have read over the materials on the oracle website as well.

My first two basic questions are:

  1. My applet does not have a static void main(String args[]){ line because I was under the impression that for applets you use a init() and start() method. Could this be the problem?

    if not, my class which contains the init and start and the other basic methods is called Start.class and is located in a bin/ directory. Am I able to edit the manifest which is included in the .jar exported from eclipse and but this Start.class as the main class using Main-Class: Game.Start?
  2. Another very basic question also when it comes to directories in java or specifically in .jar archives, are folders in a path names always separated by a .? or do /'s work too?

My project name is simply Game, I have a src folder with .java files and a bin folder with .class how do I direct the manifest to the bin/start.class file?

Sorry this has been rather frustrating especially because I really want to be able to share this applet. Any help would be greatly appreciated.

Upvotes: 1

Views: 1112

Answers (2)

user unknown
user unknown

Reputation: 36229

Start.class and is located in a bin/ directory

I agree with Hovercratft about a missing main (not missing), about runnable jar (not necessary).

One problem which might exists is the exact location of files and naming of classes.

If your class name is bin.Start, because you defined a package bin (very uncommon), you need to put the bin directory into the jar.

If you didn't declare a package, you don't have a directory to put into the jar. Maybe eclipse handles this for you automatically.

To test your applet, you need a html file, and start the html file in the appletviewer. If this works, you test it in the browser. Else verify that you can start foreign applets in your browser, to make sure it is installed in the correct way.

Since you show a sloppy habit in the question of cases: Start.class or start.class: This is significant for Java. Use initial uppercase names everywhere.

Upvotes: 1

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285415

1) My applet does not have a static void main (args[]){ line because I was under the impression that for applets you use a init() and start() method. Could this be the problem?

No, this is not a problem, as Applets and JApplets do not use main methods to run. Note that some may have main methods that may be used to allow the coder to test the code in a non-applet environment, but when run as an applet, the main methods are ignored.

2) Another very basic question also when it comes to directories in Java or specifically in .jar archives, are folders in a path names always separated by a "."? or do "/"'s work too?

the directeries in jar files use "/". Please check that you are not trying to use resources as Files since jar files do not hold files (but rather resources).

My project name is simply Game, I have a src folder with .java files and a bin folder with .class how do I direct the manifest to the bin/start.class file?

Consider showing the structure of your jar file and also a small test html file where you try to run the applet.

Upvotes: 2

Related Questions