You can use the following types of images.
To improve performance in these areas, use the following techniques:
Double buffering (for instance, for animation, draw the image off-screen and load all at once).
Overriding the default, update() function
public void update(Graphics g) { paint(g); } |
Custom layout managers. If you want custom behavior, GUI performance is best if you write your own.
Events. The JDK 1.1 has a more efficient event model than JDK 1.0.
Repaint only the damaged regions (use ClipRect).
To improve (asynchronous) loading performance, use your own imageUpdate() method to override imageUpdate(). imageUpdate() can cause more repainting than you might want..
//wait for the width information to be loaded while (image.getWidth(null) == -1 { try { Thread.sleep(200); } catch(InterruptedException e) { } } if (!haveWidth) { synchronized (im) { if (im.getWidth(this) == -1) { try { im.wait(); } catch (InterruptedException) { } } } //If we got this far, the width is loaded, we will never go thru // all that checking again. haveWidth = true; } ... public boolean imageUpdate(Image img, int flags, int x, int y, int width, \ int height) { boolean moreUpdatesNeeded = true; if ((flags&ImageObserver.WIDTH)!= 0 { synchronized (img) { img.notifyAll(); moreUpdatesNeeded = false; } } return moreUpdatesNeeded; } |
Pre-decoding and storing the image in an array will improve performance. Image decoding time is greater than loading time. Pre-decoding using PixelGrabber and MemoryImageSource should combine multiple images into one file for maximum speed. These techniques are more efficient than polling.