30-08-2011, 12:32 PM
Code:
import java.awt.*;
import java.applet.*;
/*
<applet code=ObservedImageLoad width=300 height=300>
<param name="img" value="smile.jpg">
</applet>
*/
public class ObservedImageLoad extends Applet
{
Image img;
boolean error=false;
String imgname;
public void init()
{
setBackground(Color.blue);
imgname = getParameter("img");
img = getImage(getDocumentBase(), imgname);
}
public void paint(Graphics g)
{
if(error)
{
Dimension d = getSize();
g.setColor(Color.red);
g.fillRect(0,0,d.width,d.height);
g.setColor(Color.black);
g.drawString("Image not found" + imgname,10,d.height/2);
}
else
{
g.drawImage(img,0,0,this);
}
}
public void update(Graphics g)
{
paint(g);
}
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
{
if((flags & SOMEBITS) != 0 )
{
//repaint();
repaint(x,y,w,h);
}
else if((flags & ABORT) != 0)
{
error = true;
repaint();
}
return (flags & (ALLBITS|ABORT)) == 0;
}
}