本文整理匯總了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;
}