This content has been marked as final. Show 16 replies
Given the little information you've provided, my guess is either a bug in your code, or evil magic pixies have prevented it from working.
If it's a bug, you didn't refer to the gif properly in your code, and/or you didn't package it properly.
I'd guess it's something with the packaging.
The picture works fine when I run an html file on my computer with the <applet> code.
It's the jar file that doesn't display it.
I've never used jar files before. I'm using JCreator, I simply clicked "Create Jar File" and hoped it would all work. It listed the files it added, and it seemed to add all the necessary ones.
So I'm not sure what to do.
Is the gif file in the jar file? What's its path in the jar?
How do you refer to the gif in your code?
I'm not sure what it's path IN the jar file is, now that I think of it.
I use it in my code like this:
Although I guess I would need to change the path to the jar's .gif path, huh?
backImage = getImage(getCodeBase(), "Pong.gif");
Only problem is I don't know how to find it. How do I find the path of the .gif in the jar?
Only problem is I don't know how to find it. How do II don't use JCreator so I have no idea how to do it there.
find the path of the .gif in the jar?
If you have the JDK installed, then on the command line you can do:
(substituting your actual jar file name of course), and it should list the jar file contents.
jar tvf MyJar.jar
I use it in my code like this:Probably. I think that getCodeBase returns the URL to the jar file, and if Pong.gif is not at the root of the jar file, the above wouldn't find it. I could be wrong though. You should feel free to add some debugging statements to the code to see if the values look right.
Although I guess I would need to change the path to
> backImage = getImage(getCodeBase(), "Pong.gif");
the jar's .gif path, huh?
Well, I did what you said on the command line.
Here's what it gave me:
0 Fri Dec 29 20:19:52 PST 2006 META-INF/
71 Fri Dec 29 20:19:52 PST 2006 META-INF/MANIFEST.MF
173 Fri Dec 29 16:54:56 PST 2006 Applet.html
4052 Fri Dec 29 19:54:58 PST 2006 Ball.class
4301 Fri Dec 29 19:54:56 PST 2006 Ball.java
3918 Tue Jun 24 15:57:36 PDT 2003 beep_1.au
3138 Tue Jun 24 15:58:34 PDT 2003 beep_2.au
5540 Fri Dec 29 19:48:48 PST 2006 Main.class
3949 Fri Dec 29 19:48:46 PST 2006 Main.java
1996 Fri Dec 29 20:19:24 PST 2006 Player.class
1605 Fri Dec 29 20:19:24 PST 2006 Player.java
3003 Fri Dec 29 15:00:16 PST 2006 Pong.GIF
Looks like Pong.GIF is in the root, doesn't it?
Not sure why it wouldn't be working.
I don't really understand the getCodeBase(), I kinda just... use it. Is that the problem?
It looks like the problem is that you referred to "Pong.gif" in the code, but it's "Pong.GIF" in the jar. Jar pathnames are case-sensitive, apparently.
Ah, that was the problem.
Sorry about that. Not really worth a whole topic just to find out it's case sensitive in path names.
That's pretty lame though.
Thanks for the help. =)
Here's what it gave me:Out of interest, why do you include the java source files and the Applet.html file in your jar? Since this is an Applet, it normally makes sense to keep the size of the jar as small as possible.
Yeah, I was kind of lazy and just zipped everything up.
I should probably remove the excess files that I had in the same folder.
There. All better.
Message was edited by:
Sometimes I've done that (put everything in the jar, including source) just because it meant I had a convenient backup of the source that way. This was for small projects where the source code files didn't add much weight to the jar.
Well, here's the game:
Enjoy how badly made it is!
I gave it a shot. My first attempt at a graphical game.