Article View: borland.public.jbuilder.java.language
Article #742Re: validating URL
From: Alan Shiers
Date: Mon, 20 Dec 2004 18:18
Date: Mon, 20 Dec 2004 18:18
36 lines
2124 bytes
2124 bytes
You can ignore the last post. Further research has revealed the following
which solved my dilemma:
JLabel label = new JLabel();
public void setLabelIcon(Object newValue)
{
try
{
String st = (String)newValue;
st = st.toLowerCase();
if((st.indexOf("gif") == -1) && (st.indexOf("jpg") == -1))
{
JOptionPane.showMessageDialog(null, "The URL provided does not
contain a\nreference to either a gif or jpg image!", "Image URL",
JOptionPane.PLAIN_MESSAGE);
return;
}
ImageIcon icon = new ImageIcon(new URL(st));
int status = icon.getImageLoadStatus();
if(status == MediaTracker.ABORTED || status == MediaTracker.ERRORED)
{
JOptionPane.showMessageDialog(null, "The URL provided is not
valid!\nPlease check your syntax.", "Image URL", JOptionPane.PLAIN_MESSAGE);
return;
}
label.setIcon(icon);
label.setText("");
}
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:
<41c71850@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41c6ff3c$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,8944089311d48c74 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 References: <41c6ff3c$1@newsgroups.borland.com> Subject: Re: validating URL Date: Mon, 20 Dec 2004 14:18:00 -0400 Lines: 39 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: <41c71850@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1103566928 24.222.101.2 (20 Dec 2004 10:22:08 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail