本文整理匯總了Java中java.awt.MediaTracker.statusID方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaTracker.statusID方法的具體用法?Java MediaTracker.statusID怎麽用?Java MediaTracker.statusID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.MediaTracker
的用法示例。
在下文中一共展示了MediaTracker.statusID方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: preload
import java.awt.MediaTracker; //導入方法依賴的package包/類
/**
* Preload the image.
*/
public void preload() {
synchronized (loadingLock) {
if (image == null) {
MediaTracker mt = new MediaTracker(_c);
Image im;
try {
// Explicitly check that the URI is valid before
// letting createImage go off and look for it, as the
// error it throws is cryptic.
URL url = getResourceLocator().toURL();
InputStream is = url.openStream();
is.close();
im = Toolkit.getDefaultToolkit().createImage(url);
mt.addImage(im, 0);
mt.waitForID(0);
if (mt.statusID(0, false) == MediaTracker.COMPLETE) {
image = im;
}
} catch (Exception e) {
logger.log(Level.WARNING, "Failed to load image from: "
+ getResourceLocator(), e);
}
}
}
}
示例2: loadImage
import java.awt.MediaTracker; //導入方法依賴的package包/類
/** Ensures the given AWT image is fully loaded. */
public static boolean loadImage(final Image image) {
if (image instanceof BufferedImage) return true;
final MediaTracker tracker = new MediaTracker(OBS);
tracker.addImage(image, 0);
try {
tracker.waitForID(0);
}
catch (final InterruptedException exc) {
return false;
}
if (MediaTracker.COMPLETE != tracker.statusID(0, false)) return false;
return true;
}
示例3: getImage
import java.awt.MediaTracker; //導入方法依賴的package包/類
/**
* Gets the image using the specified dimension.
*
* @param d The <code>Dimension</code> of the requested
* image. Rescaling will be performed if necessary.
* @return The <code>Image</code> with the required dimension.
*/
public Image getImage(Dimension d) {
final Image im = getImage();
if (im == null
|| (im.getWidth(null) == d.width
&& im.getHeight(null) == d.height)) return im;
synchronized (loadingLock) {
final Image cached = scaledImages.get(d);
if (cached != null) return cached;
MediaTracker mt = new MediaTracker(_c);
try {
// Use SCALE_REPLICATE instead of SCALE_SMOOTH to avoid
// ClassCastException.
// TODO (perhaps): find a better solution.
Image scaled = im.getScaledInstance(d.width, d.height,
Image.SCALE_REPLICATE);
mt.addImage(scaled, 0, d.width, d.height);
mt.waitForID(0);
int result = mt.statusID(0, false);
if (result == MediaTracker.COMPLETE) {
scaledImages.put(d, scaled);
} else {
logger.warning("Scaling image: " + getResourceLocator()
+ " => " + result);
}
return scaled;
} catch (Exception e) {
logger.warning("Failed to scale image: " + getResourceLocator()
+ "\r\nProblem: " + e );
}
}
return null;
}