Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Java Client Applet - Storing it AppData

Posted on 2010-08-17
15
264 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:UrbanTwitch
  • 8
  • 7
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 33461269
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
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461357
oh so then how would i tell the jar file to download those inside the jar file instead from the internet?
0
 
LVL 92

Expert Comment

by:objects
ID: 33461389
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461399
So where would I put the new URL i formed... inside replacing the tile%.png?
0
 
LVL 92

Expert Comment

by:objects
ID: 33461451
you already use getResource()


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

0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461459
wait wait wait *scratches head*... so I am already using it?
0
 
LVL 92

Expert Comment

by:objects
ID: 33461477
so in your case you need to include the line_tile (and any other resources) in your jar
0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461527
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
 
LVL 92

Expert Comment

by:objects
ID: 33461534
yes
0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461547
Wait... so then how do I draw a URL? :S
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 33461616
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
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461645
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
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461659
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
 
LVL 92

Expert Comment

by:objects
ID: 33461661
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
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33461705
OK so now it loads up a lot faster. Around 10 seconds or so.


(we're getting here! ... time for a new Q!)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
expectj telnet failing 5 45
check java version using powershell 13 169
Selenium docs api java index 3 48
Eclipse for Java EE development 2 27
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question