Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q4002 How can I preload an image before I paint it?

irt.org | Knowledge Base | Java | Q4002 [ previous next ]

Q4002 How can I preload an image before I paint it?

Use ImageObserver interface, ImageObserver is an interface used to receive notification as an image is being generated. ImageObserver defines only one method: imageUpdate(). The following code waits until the image is completely loaded before snapping it onto the screen in a single repaint.

public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h){
    if ((flags & ALLBITS) != 0{
      repaint();
    } else if (flags & (ABORT|ERROR)) != 0){
      error = true; //file not found
      repaint();
    }
    return (flags & (ALLBITS|ABORT|ERROR)) == 0;
}

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.