本文整理汇总了Java中java.awt.MediaTracker.LOADING属性的典型用法代码示例。如果您正苦于以下问题:Java MediaTracker.LOADING属性的具体用法?Java MediaTracker.LOADING怎么用?Java MediaTracker.LOADING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.MediaTracker
的用法示例。
在下文中一共展示了MediaTracker.LOADING属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displaySplashScreen
/**
* Displays splash.png during the loading
* @return
*/
public SplashScreen displaySplashScreen() {
ImageIcon splashScreenImage = new ImageIcon();
try {
splashScreenImage.setImage(ImageIO.read(getClass().getResource(
"splash.png")));
} catch (IOException e1) {
e1.printStackTrace();
}
// while the image is not on screen
while (splashScreenImage.getImageLoadStatus() == MediaTracker.LOADING) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.printf("splash screen loading interrupted", e); //$NON-NLS-1$
}
}
// should normally be run in the EDT, but launched at once in order to
// display the screen as soon as possible
return new SplashScreen(splashScreenImage, 2000, version);
}
示例2: loadImage
public static Image loadImage(String filename, Component watcher, URL url) {
Image image = null;
if (url == null) {
System.err.println("loadImage() could not find \"" + filename + "\"");
} else {
image = watcher.getToolkit().getImage(url);
if (image == null) {
System.err.println("loadImage() getImage() failed for \"" + filename + "\"");
} else {
MediaTracker tracker = new MediaTracker(watcher);
try {
tracker.addImage(image, 0);
tracker.waitForID(0);
} catch (InterruptedException e) {
System.err.println("loadImage(): " + e);
} finally {
boolean isError = tracker.isErrorAny();
if (isError) {
System.err.println("loadImage() failed to load \"" + filename + "\"");
int flags = tracker.statusAll(true);
boolean loading = 0 != (flags & MediaTracker.LOADING);
boolean aborted = 0 != (flags & MediaTracker.ABORTED);
boolean errored = 0 != (flags & MediaTracker.ERRORED);
boolean complete = 0 != (flags & MediaTracker.COMPLETE);
System.err.println("loading: " + loading);
System.err.println("aborted: " + aborted);
System.err.println("errored: " + errored);
System.err.println("complete: " + complete);
}
}
}
}
return image;
}
示例3: getLoadedImage
/**
* Ensures the image is loaded enough (loading is fine).
*
* @param newImage to check
* @return image or null if not loaded enough.
*/
private Image getLoadedImage(final Image newImage) {
final ImageIcon imageLoader = new ImageIcon(newImage);
switch (imageLoader.getImageLoadStatus()) {
case MediaTracker.LOADING:
case MediaTracker.COMPLETE:
return imageLoader.getImage();
default:
return null;
}
}
示例4: getImage
/**
* Loads a cached image from a class offset from the ImageManager
* waiting for it to be completely loading using a MediaTracker
* @param imageName the name of the image to load
* @return the cached image
*/
public ImageIcon getImage(String imageName) {
ImageIcon image = null;
if (images.containsKey(imageName)) {
image = (ImageIcon) images.get(imageName);
} else {
URL url = getClass().getResource(imageName);
if (url == null) {
//System.out.println("ImageManager.getImage() could not find image: " + imageName);
} else {
image = new ImageIcon(getClass().getResource(imageName));
while (image.getImageLoadStatus() == MediaTracker.LOADING) {
try {
Thread.currentThread().wait(100);
} catch (InterruptedException e) {
}
}
if (image != null && image.getImageLoadStatus() == MediaTracker.COMPLETE) {
images.put(imageName, image);
} else {
//System.out.println("ImageManager.getImage() failed to load image: " + imageName);
}
}
}
return image;
}
示例5: getImage
/**
* Loads a cached image from a class offset from the ImageManager waiting for it to be completely loading using a
* MediaTracker
* @param imageName the name of the image to load
* @return the cached image
*/
public ImageIcon getImage(String imageName)
{
ImageIcon image = null;
if (images.containsKey(imageName))
{
image = (ImageIcon) images.get(imageName);
}
else
{
URL url = getClass().getResource(imageName);
if (url != null)
{
image = new ImageIcon(getClass().getResource(imageName));
while (image.getImageLoadStatus() == MediaTracker.LOADING)
{
try
{
Thread.currentThread().wait(100);
}
catch (InterruptedException e)
{
}
}
if (image != null && image.getImageLoadStatus() == MediaTracker.COMPLETE)
{
images.put(imageName, image);
}
}
}
return image;
}