Home | | Web Programming | ImageObserver

Chapter: Java The Complete Reference : The Java Library : Images

ImageObserver

ImageObserver is an interface used to receive notification as an image is being generated, and it defines only one method: imageUpdate( ). Using an image

ImageObserver

 

ImageObserver is an interface used to receive notification as an image is being generated, and it defines only one method: imageUpdate( ). Using an image observer allows you to perform other actions, such as show a progress indicator or an attract screen, as you are informed of the progress of the download. This kind of notification is very useful when an image is being loaded over a slow network.

The imageUpdate( ) method has this general form:

 

boolean imageUpdate(Image imgObj, int flags, int left, int top, int width, int height)

 

Here, imgObj is the image being loaded, and flags is an integer that communicates the status of the update report. The four integers left, top, width, and height represent a rectangle that contains different values depending on the values passed in flags. imageUpdate( ) should return false if it has completed loading, and true if there is more image to process.

The flags parameter contains one or more bit flags defined as static variables inside the ImageObserver interface. These flags and the information they provide are listed in Table 27-1.


Table 27-1   Bit Flags of the imageUpdate( ) flags Parameter

The Applet class has an implementation of the imageUpdate( ) method for the ImageObserver interface that is used to repaint images as they are loaded. You can override this method in your class to change that behavior.

Here is a simple example of an imageUpdate( ) method:

 

public boolean imageUpdate(Image img, int flags,

 

int x, int y, int w, int h) { if ((flags & ALLBITS) == 0) {

 

System.out.println("Still processing the image."); return true;

 

} else {

 

System.out.println("Done processing the image."); return false;

 

}

 

}

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Java The Complete Reference : The Java Library : Images : ImageObserver |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.