Applet and .jar files

M

Marcin Siewiera

I wrote an applet(board game) which is loaded from .jar file. The
applet is loading somehow too slow, its just 120 kB. I reckon the
reason is the applet is getting what it needs from .jar, and as i load
images one by one it takes a while... Is there any way to download
whole .jar when applet starts?

I access images with

URL path=null;
try{
path=getClass().getResource("/game/images/"+filename);
image=Toolkit.getDefaultToolkit().getImage(path);
MediaTracker imgTrack=new MediaTracker(parent);

imgTrack.addImage(image,0);
// waits until board image is loaded
try {
imgTrack.waitForAll();
}
catch (InterruptedException e) {
}


applet's URL www.bescres.net/play_html.htm (U need JRE 1.42 to run
applet correctly)
I appreciate any suggestions
 
P

Paul Lutus

Marcin said:
I wrote an applet(board game) which is loaded from .jar file. The
applet is loading somehow too slow, its just 120 kB. I reckon the
reason is the applet is getting what it needs from .jar, and as i load
images one by one it takes a while... Is there any way to download
whole .jar when applet starts?

You can download all the images in advance using Mediatracker (and as you
appear to be doing for one image), but you will need to figure out how to
maximize the degree to which you download what you need, apart from images.
 
T

Thomas Fritsch

Marcin said:
I wrote an applet(board game) which is loaded from .jar file. The
applet is loading somehow too slow, its just 120 kB. I reckon the
reason is the applet is getting what it needs from .jar, and as i load
images one by one it takes a while... Is there any way to download
whole .jar when applet starts?
The browser *does* already dowload the whole .jar anyway, when the
applet starts. ==> The cause of the experienced slowlyness of your image
loading is somewhere else.
I access images with

URL path=null;
try{
path=getClass().getResource("/game/images/"+filename);
image=Toolkit.getDefaultToolkit().getImage(path);
MediaTracker imgTrack=new MediaTracker(parent);

imgTrack.addImage(image,0);
// waits until board image is loaded
try {
imgTrack.waitForAll();
}
catch (InterruptedException e) {
}
Do you load one image after the other, or all images in parallel?
I guess you do the first (although you didn't post the looping part of
your code). The second approach will probably give better performance.
applet's URL www.bescres.net/play_html.htm (U need JRE 1.42 to run
applet correctly)
I appreciate any suggestions

<angry>
Your silly applet did not allow me to close the modal pop-up dialog,
therefore I was not able to close my browser (or leave your web-page),
except by killing the browser with the task-manager.
</angry>
 
T

Thomas Fritsch

Thomas said:
<angry>
Your silly applet did not allow me to close the modal pop-up dialog,
therefore I was not able to close my browser (or leave your web-page),
except by killing the browser with the task-manager.
</angry>
The problem above does not occur anymore.
Thank you for fixing it. And sorry for my offence!
 
M

Martin

Thomas Fritsch said:
The problem above does not occur anymore.
Thank you for fixing it. And sorry for my offence!

Sorry! My fault. I appreciate your help, servlet starts faster, and
modals are just where they should be. Thank YOU.
 
C

Christian Hvid

I would suggest that you remove the images from your jar and put them
along side the jar on your webserver. You will get the same
compression as gifs/pngs already are fully compressed and the applet
will initialise faster. You can also consider creating a single
graphics sheet with all your images in it and crop them from that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top