Article View: borland.public.jbuilder.java.language
Article #741validating URL
From: Alan Shiers
Date: Mon, 20 Dec 2004 16:31
Date: Mon, 20 Dec 2004 16:31
29 lines
1736 bytes
1736 bytes
Hi there,
I'm working on a project where I'm making use of an ImageIcon object. For
its contructor it takes a URL. I have to surround the instance of the
ImageIcon with a try catch block to catch any MalformedURLException. That's
fine. But, if syntactically the URL is correct, it isn't necessarily
pointing to an actual resource on the net, and it won't throw any exception
in this case!
If I'm trying to pass to an ImageIcon a URL to a *.gif file somewhere on the
net, and I get the path wrong, how do I programmatically determine that?
Alan
JLabel label = new JLabel();
public void setLabelIcon(Object newValue)
{
try
{
label.setIcon(new ImageIcon(new URL((String)newValue)));
...
}catch(Exception e)
{
JOptionPane.showMessageDialog(null, "The URL provided is
malformed!\nBe sure it begins with \"http://\"", "Image URL",
JOptionPane.PLAIN_MESSAGE);
}
...
}
Technical Details
Message-ID:
<41c6ff3c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f74b3,8944089311d48c74,start X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Alan Shiers" <ashiers@hfx.eastlink.ca> Newsgroups: borland.public.jbuilder.java.language Subject: validating URL Date: Mon, 20 Dec 2004 12:31:02 -0400 Lines: 31 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 24.222.101.2 Message-ID: <41c6ff3c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1103560508 24.222.101.2 (20 Dec 2004 08:35:08 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail