Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem getting ImageIcons to recover from errors

Status
Not open for further replies.

robertfleder

Programmer
Jan 13, 2002
8
US

I have about 25 icons to load. From some servers, I do not get a successful load. The results are random. I tried to use this status to reinstiated the image and the icon, but once a bad status it never changes. (Java 1.4, IE 6.0 IIS server). BTW, results vary based on server load.
Here's the code:
private ImageIcon getIcon(String f) {
Image im;
ImageIcon ii = null;
int retries = 3;
try {
while( retries > 0 ) {
im = getImage(f);
ii = new ImageIcon(im);
System.out.println("Loading: "+f+ " Status: "+
ii.getImageLoadStatus());
while(ii.getImageLoadStatus()==MediaTracker.LOADING )
try {
Thread.sleep(500);
} catch (Exception e) {}
if(ii.getImageLoadStatus() == MediaTracker.COMPLETE)
retries=0;
if( retries > 0 )
System.out.println("Load status "+
ii.getImageLoadStatus()+ " for: "+f);
retries--;
}
} catch( Exception e) {
System.out.println("Bad Filename: "+f);
System.out.println("Error: "+e);
}
return ii;
}



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top