What's new

Another Java question (1 Viewer)

Jay H

Senior HTF Member
Joined
Mar 22, 1999
Messages
5,654
Location
Pittsfield, MA
Real Name
Jay
Image img = getImage(getDocumentBase(),Input_name);
if (img == null) System.out.println("Bongo for Mongo");
Input_name is simply a String taken from a PARAM earlier on.
Now the idea here is that if for some reason, Input_name doesn't exist in the applet base directory, typo or otherwise, that I'd be able to display a "file not found" type of image on my applet. However, I cannot seem to catch the failure to load the image. All my documentation states that getImage(URL,String) shall return a new thread with the image if found and null if not. So how come I'm never getting that System msg? I've tried to TRY and CATCH it but that doesn't work and it seems getImage is returning something whether it finds Input_name or not?
Any ideas? I've even tried img.equals(null) and that doesn't work.
Jay
 

Bill Slack

Supporting Actor
Joined
Mar 16, 1999
Messages
837
"getImage

public Image getImage(URL url,

String name)

Returns an Image object that can then be painted on the screen. The url argument must specify an absolute URL. The name argument is a specifier that is relative to the url argument.

This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen.

Parameters:

url - an absolute URL giving the base location of the image.

name - the location of the image, relative to the url argument.

Returns:

the image at the specified URL.

See Also:

Image" -- Java API Documentation

Doesn't return 'null' if it doesn't exist. It must actually create a (0,0) image? You could check whether the height or width is 0, which would mean there is no data, but it apparently does instantiate it, no matter what.

I'm just going off the documentation here, I've not tried this myself.
 

Jay H

Senior HTF Member
Joined
Mar 22, 1999
Messages
5,654
Location
Pittsfield, MA
Real Name
Jay
Yahh, I swear to the Java Gods I thought it said it returns Null, it could possibly be another getImage from another class... Oh well, I thought I was going crazy for a second. I am using a check to Img.getWidth(this) == -1 to see if there is an image or not. It works fine...

Thanks,

Jay
 

Users who are viewing this thread

Sign up for our newsletter

and receive essential news, curated deals, and much more







You will only receive emails from us. We will never sell or distribute your email address to third party companies at any time.

Forum statistics

Threads
357,068
Messages
5,129,998
Members
144,283
Latest member
Nielmb
Recent bookmarks
0
Top