Here you can find the source of waitForImage(java.awt.Image image)
private static void waitForImage(java.awt.Image image)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 Google, Inc.//from w ww . j av a 2 s. c om * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Google, Inc. - initial API and implementation *******************************************************************************/ import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; public class Main { /** * Waits until image is fully loaded, so ready for drawing. */ private static void waitForImage(java.awt.Image image) { BufferedImage bufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bufferedImage.createGraphics(); // prepare observer final Object done = new Object(); ImageObserver imageObserver = new ImageObserver() { public boolean imageUpdate(java.awt.Image img, int flags, int x, int y, int width, int height) { if (flags < ALLBITS) { return true; } else { synchronized (done) { done.notify(); } return false; } } }; // draw Image with wait synchronized (done) { boolean completelyLoaded = g2.drawImage(image, 0, 0, imageObserver); if (!completelyLoaded) { while (true) { try { done.wait(0); break; } catch (InterruptedException e) { } } } } // clean up g2.dispose(); } }