FileDocCategorySizeDatePackage
Utilities.javaAPI DocExample2681Mon Apr 05 11:09:44 BST 1999None

Utilities

public class Utilities extends Object

Fields Summary
private static final Component
sComponent
private static final MediaTracker
sTracker
private static int
sID
Constructors Summary
Methods Summary
public static java.awt.ImageblockingLoad(java.lang.String path)

    Image image = Toolkit.getDefaultToolkit().getImage(path);
    if (waitForImage(image) == false) return null;
    return image;
  
public static java.awt.ImageblockingLoad(java.net.URL url)

    Image image = Toolkit.getDefaultToolkit().getImage(url);
    if (waitForImage(image) == false) return null;
    return image;
  
public static voidcenterFrame(java.awt.Frame f)

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension d = f.getSize();
    int x = (screen.width - d.width) / 2;
    int y = (screen.height - d.height) / 2;
    f.setLocation(x, y);
  
public static java.awt.FramegetNonClearingFrame(java.lang.String name, java.awt.Component c)

    final Frame f = new Frame(name) {
      public void update(Graphics g) { paint(g); }
    };
    sizeContainerToComponent(f, c);
    centerFrame(f);
    f.setLayout(new BorderLayout());
    f.add(c, BorderLayout.CENTER);
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) { f.dispose(); }
    });
    return f;
  
public static java.awt.image.BufferedImagemakeBufferedImage(java.awt.Image image)

    return makeBufferedImage(image, BufferedImage.TYPE_INT_RGB);
  
public static java.awt.image.BufferedImagemakeBufferedImage(java.awt.Image image, int imageType)

    if (waitForImage(image) == false) return null;

    BufferedImage bufferedImage = new BufferedImage(
        image.getWidth(null), image.getHeight(null),
        imageType);
    Graphics2D g2 = bufferedImage.createGraphics();
    g2.drawImage(image, null, null);
    return bufferedImage;
  
public static voidsizeContainerToComponent(java.awt.Container container, java.awt.Component component)

    if (container.isDisplayable() == false) container.addNotify();
    Insets insets = container.getInsets();
    Dimension size = component.getPreferredSize();
    int width = insets.left + insets.right + size.width;
    int height = insets.top + insets.bottom + size.height;
    container.setSize(width, height);
  
public static booleanwaitForImage(java.awt.Image image)

  
       
    int id;
    synchronized(sComponent) { id = sID++; }
    sTracker.addImage(image, id);
    try { sTracker.waitForID(id); }
    catch (InterruptedException ie) { return false; }
    if (sTracker.isErrorID(id)) return false;
    return true;