本文整理汇总了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;
}