How do I make sure an Image is loaded before I try to display it?

John Zukowski

You can use the AWT MediaTracker to start and wait for the loading of an Image object.

Image image = ...;
MediaTracker tracker = new MediaTracker(component or this);
tracker.addImage(image, 0);
try {
  tracker.waitForAll();
} catch (InterruptedException e) {
  System.out.println("Interrupted while loading Image");
}

At this point, if everything went okay, the image would be loaded. You can check the status with statusAll() or statusID() to see if they loaded successfully.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact