FileDocCategorySizeDatePackage
RightSizer.javaAPI DocExample1693Mon Apr 05 10:46:14 BST 1999None

RightSizer

public class RightSizer extends ApplicationFrame

Fields Summary
private Image
mImage
Constructors Summary
public RightSizer(URL url)

    super("RightSizer v1.0");
    mImage = Toolkit.getDefaultToolkit().getImage(url);
    rightSize();
  
Methods Summary
public booleanimageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)

    if ((infoflags & ImageObserver.ERROR) != 0) {
      System.out.println("Error loading image!");
      System.exit(-1);
    }
    if ((infoflags & ImageObserver.WIDTH) != 0 &&
        (infoflags & ImageObserver.HEIGHT) != 0)
      rightSize();
    if ((infoflags & ImageObserver.SOMEBITS) != 0)
      repaint();
    if ((infoflags & ImageObserver.ALLBITS) != 0) {
      rightSize();
      repaint();
      return false;
    }
    return true;
  
public static voidmain(java.lang.String[] args)

    String url = "http://java.oreilly.com/" + 
        "news/knudsen/graphics/bite-size_banner.gif";
    if (args.length > 0) url = args[0];
    new RightSizer(new URL(url));
  
public voidpaint(java.awt.Graphics g)

    Insets insets = getInsets();
    g.drawImage(mImage, insets.left, insets.top, this);
  
private voidrightSize()

    int width = mImage.getWidth(this);
    int height = mImage.getHeight(this);
    if (width == -1 || height == -1) return;
    addNotify();
    Insets insets = getInsets();
    setSize(width + insets.left + insets.right,
        height + insets.top + insets.bottom);
    center();
    setVisible(true);
  
public voidupdate(java.awt.Graphics g)

    paint(g);