0


I have some annoying problem with java applet.

Basically I made java applet that works fine. After finishing it, i wanted to embed it in html file and that is where my problem began.

When i compiled applet i saw 7 more .class files besides my basic .class file (Game$1.class,Game$2.class,Game$3.class,...,Game$7.class,Game.class)

I tried to ignore the rest of .class files and to embed just Game.class into html but it didn't work. When I tried to run applet it just showed just blank html page.

I tried same html code with simple "Hello world" applet and it worked so I assume that html file is correct

My html file is located in bin folder just as whole java package.

Can anyone help me with this problem?

4 Answers 4

3

Those are your anonymous inner classes in compiled form. You can't leave them out of the bundle, your applet won't work without them.

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

1 Comment

Actually i don't leave them out. All classes (anonymous inner classes and 'normal' class) are in the same folder from very beginning.
2

As mentioned by others, the extra classes are because of anonymous inner classes that are in the code. They must be on the run-time class-path of the app. for it to function properly.

There are a number of ways to fix to this problem. Here are 2:

  1. Put all the anonymous inner classes in the same bin location as the main applet class.
  2. Put all classes into one Jar file, put the Jar file in the bin dir., mention it in the archive attribute of the applet.

BTW: Why is this an applet at all? What does the browser wrapper bring to the applet (besides challenges)? If 'nothing', better to launch the applet using Java Web Start.

2 Comments

Actually anonymous inner classes were at the same folder as game.class file from the very beginning. Path goes something like this: .../bin/pack/ and in pack folder I have all classes together. So it won't work when i declare game.class in code attribute. I also tried solution with jar file in archive attribute and it won't work also. I just added archive = "game.jar" right next to code attribute and it won't work. Any other ideas?
"Any other ideas?" 1) Answer questions that I ask. 2) Load the applet HTML using Appleteer & copy/paste what it reports.
1

Well, the sort of class names you have given it seems you have some inner classes in your class. Can you post the code for Game.java to have better understanding.

1 Comment

You can get .java file from here alas.matf.bg.ac.rs/~mi09052/Game.java .Basically my problem is how to embed applet in html file when i have anonymous inner classes. All .class files are in the same folder and in code attribute of html file I declare just Game.class and it won't work. Any ideas?
1

Is your problem just that, in your <applet> tag, you're specifying the URL of the .class file directly instead of using a .jar file?

In that case, perhaps you should read Lesson: Packaging Programs in JAR Files from the Java Tutorials.

2 Comments

I also tried with .jar file. I located it in the same folder as my html file and java package folder and it won't work.
@B.P.: Your .jar file contains all the .class files? In the correct folder structure? Your HTML references the URL to the .jar file, not the URL to any specific .class file? If that's the case, can you elaborate on what you mean by "it won't work"?

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.