Java Client Applet - Storing it AppData

If you're using Windows (and why?), you'll know when you play Java Applet games that they store their data locally to load faster when you play them again and again.

For example - take this image:
 Loading up .jar fiels, sound files, and image files!See the jar files? Inside those folders are also mp3 files.
This is the game: http://minecraft.net/game/

How do I do this for my java applet?
I have tried google but alas -- no help.

Thank you.
LVL 5
UrbanTwitchAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
if its an applet then theres nothing you really need to do. resources should get cached automatically for you.
For resurces like images/audio its often a good idea to jar them up so its just one download
0
UrbanTwitchAuthor Commented:
oh so then how would i tell the jar file to download those inside the jar file instead from the internet?
0
objectsCommented:
theres no need to have them available anywhere but the jar so you don't need to specify which to use
To get the URL of a resource in a jar use the Class.getResource() method

http://helpdesk.objects.com.au/java/how-to-get-url-to-a-resource-in-same-directory-as-a-class
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

UrbanTwitchAuthor Commented:
So where would I put the new URL i formed... inside replacing the tile%.png?
0
objectsCommented:
you already use getResource()


                        tiles[i] = ImageIO.read(getClass().getResource(
                                    String.format("line_tile/t%d.png", i)));

0
UrbanTwitchAuthor Commented:
wait wait wait *scratches head*... so I am already using it?
0
objectsCommented:
so in your case you need to include the line_tile (and any other resources) in your jar
0
UrbanTwitchAuthor Commented:
So it would be like this.
Correct?
URL tile[i] = MyClass.class.getResource(String.format("line_tile/t%d.png", i));

Open in new window

0
objectsCommented:
yes
0
UrbanTwitchAuthor Commented:
Wait... so then how do I draw a URL? :S
0
objectsCommented:
You're already reading a url and displaying it

http://helpdesk.objects.com.au/java/how-do-i-read-an-image-from-a-url
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UrbanTwitchAuthor Commented:
I changed
Image[] tiles;
to
URL[] tiles;

I then added import java.net.URL; with the other imports

and then I have this:

                  tiles = new URL[NUM_TILES];
                  for (int i = 0; i < NUM_TILES; i++) {
                                tiles[i] = tileGen.class.getResource(String.format("line_tile/t%d.png", i));
                      //tiles[i] = ImageIO.read(getClass().getResource(String.format("line_tile/t%d.png", i)));
                  }

and now I am getting this:

C:\wamp\www\mystikrpg\tileGen.java:994: cannot find symbol
symbol  : method drawImage(java.net.URL,int,int,tileGen.GamePanel)
location: class java.awt.Graphics
                              g.drawImage(tiles[index], 32 * col, 32 * row, this);
                               ^
1 error

Tool completed with exit code 1

Open in new window

0
UrbanTwitchAuthor Commented:
Wait I think i found it out:
This look good?
tiles = new Image[NUM_TILES];
                  for (int i = 0; i < NUM_TILES; i++) {
					  Toolkit tk = this.getToolkit();
					  		tiles[i] = tk.getImage(this.getClass().getResource(String.format("line_tile/t%d.png", i)));
}

Open in new window

0
objectsCommented:
you didn't need any code change :)

> so in your case you need to include the line_tile (and any other resources) in your jar
0
UrbanTwitchAuthor Commented:
OK so now it loads up a lot faster. Around 10 seconds or so.


(we're getting here! ... time for a new Q!)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.