import java.awt.*;
import java.applet.*;
import java.awt.image.*;
// This applet draws an image on Applet
public class ImageTrace extends Applet {
Image img;
Observer myTracker=new Observer(this);
public void init() {
img=getImage(getDocumentBase(),"beans.gif");
}
public void paint(Graphics g) {
int w=img.getWidth(myTracker);
int h=img.getHeight(myTracker);
String status="w="+Integer.toString(w)
+" h="+Integer.toString(h);
g.drawImage(img,0,0,myTracker);
g.drawString(status,0,45);
}
}
class Observer implements ImageObserver{
//Save the component that call this object
Component component;
public Observer(Component comp){
component=comp;
}
public boolean imageUpdate(Image img,int infoflags,
int x,int y,int width,int height){
if ((infoflags & ImageObserver.ALLBITS)!=0) {
System.out.println("Loading image completed ");
component.repaint();
return false;
}
if ((infoflags & ImageObserver.WIDTH)!=0) {
System.out.println("Image height "+width);
}
if ((infoflags & ImageObserver.HEIGHT)!=0) {
System.out.println("Image width "+height);
}
if ((infoflags & ImageObserver.SOMEBITS)!=0) {
System.out.println("pixels comming : ("
+x+","+y+","+width+","+height+")");
}
return true;
}
}