471,112 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,112 software developers and data experts.

applet loading of images -- network or JAR approach faster?

hi all,

i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and incurred a network hit per image file.

i wanted to avoid the overhead of a separate network connection for each image file, so i bundled all the images into the JAR file. yet, somehow, the loading time for the applet is slower now! i'm totally mystified.

i put the code for loading each image into a separate thread as well. here's the thread code:

Expand|Select|Wrap|Line Numbers
  1. public class ImageLoaderThread extends Thread {
  2.  
  3.     private Hashtable images;
  4.     private DesignApplet applet;
  5.  
  6.     public ImageLoaderThread(DesignApplet applet, Hashtable images, String imageFile) {
  7.         super(imageFile);
  8.         this.images = images;
  9.         this.applet = applet;
  10.     }
  11.  
  12.     public void run() {
  13.         try {
  14.  
  15.             System.out.println("Starting to load image ...");
  16.  
  17.             String imageFile = getName();
  18.             InputStream is = applet.getClass().getResourceAsStream(imageFile);
  19.             int arraySize = is.available() * 2; // CH: create extra space just in case
  20.             System.out.println("Image Loader Thread: " + imageFile + "bytes available: " + arraySize);
  21.             BufferedInputStream bis = new BufferedInputStream(is);
  22.             byte[] byBuf = new byte[arraySize];  // a buffer large enough for our image
  23.             int byteRead = bis.read(byBuf, 0, arraySize);
  24.             Image buttonImage = Toolkit.getDefaultToolkit().createImage(byBuf);
  25.             images.put(imageFile, buttonImage);
  26.         }
  27.         catch(Exception e) {
  28.             System.out.println("Exception while loading: " + getName());
  29.             e.printStackTrace();
  30.         }
  31.  
  32.     }
  33.  

imageFile is the name of an image file stored in the JAR file. it's not stored on the server anywhere, so i know the file must be created from the JAR file. despite this, the speed of image creation seems tied to the network. in other words, when i attempt to load the applet over a slow link, it takes longer to load than over a fast link.

any ideas? i'm seriously stumped and could use help. what am i doing wrong? my goals are to minimize loading time of the applet while minimizing network hits for the server.

thanks!

p.s. if you want to play w/ the applet, click on the following link and click the "Customize" button: http://www.cengraving.com/s/z/Photo-plaques/PP024.jsp
Nov 6 '06 #1
0 2073

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Don | last post: by
4 posts views Thread by Adrian MacNair | last post: by
reply views Thread by NoaGross | last post: by
1 post views Thread by brickled | last post: by
reply views Thread by shanmukhi | last post: by
reply views Thread by shanmukhi | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.