Java Image Wait waitForImage(Image image)

Here you can find the source of waitForImage(Image image)

Description

Waits for an image to load fully.

License

Minecraft Mod Public

Parameter

Parameter Description
image The image to load.

Return

Returns true if everything goes well, false on error.

Declaration

public static boolean waitForImage(Image image) 

Method Source Code


//package com.java2s;
import java.awt.*;

public class Main {
    /**//from w ww  .  java  2  s  .co  m
     * Required by waitForImage.
     */
    private static final Component sComponent = new Component() {
    };
    /**
     * Required by waitForImage.
     */
    private static final MediaTracker sTracker = new MediaTracker(sComponent);
    /**
     * Required by waitForImage.
     */
    private static int sID = 0;

    /**
     * Waits for an image to load fully. Returns true if everything goes well,
     * false on error. This method should support multi-threading (not tested).<br>
     * From <link>http://examples.oreilly.com/java2d/examples/Utilities.java</link><br>
     * In: Knudsen, J. 1999. Java 2D Graphics. O'Reilly. Page 198.<br>
     * @param image The image to load.
     * @return Returns true if everything goes well, false on error.
     */
    public static boolean waitForImage(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;
    }
}

Related

  1. waitFor(Image image)
  2. waitForImage(Image image)
  3. waitForImage(Image image)
  4. waitForImage(Image image, Component c)
  5. waitForImage(Image image, Component component)
  6. waitForImage(Image image, Component component)
  7. waitForImage(java.awt.Image image)