Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Observed Image Load Java source code
#1

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;
  }
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.