Usig Images from the web in Java
Hi guys I'm having problems getting this little program to function properly.
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class Test
{
public static void main(String[] args) throws Exception
{
URL imageLocation = new URL("https://duke.dev.java.net/images/iconSized/duke.gif");
JOptionPane.showMessageDialog(null, "Hello", "Title",
JOptionPane.PLAIN_MESSAGE, new ImageIcon(imageLocation));
System.exit(0);
}
}
Expected result:
a dialog box with "hello" in it, and an image somewhere in the mix.
Current Result:
a dialog box with hello in it... No image!
Can someone tell me why is the URL object not working properly?
thank you very much.
-Zeek
Re: Usig Images from the web in Java
Do you get any error messages?
System.exit(0);
By the way, that line of code is pointless as the program is about to exit anyway.
Re: Usig Images from the web in Java
Well no I don't get any error message. It runs perfectly but the output is not as expected. It is as if I just created a window with them message hello in it, and ignored the image. Its kinda weird and annoying. But thanks for the tip on that line of code! :D
Re: Usig Images from the web in Java
Are you sure that the url is correct? Have you typed it into a browser?
Re: Usig Images from the web in Java
As a nooby java person, i will just say this: duke.dev.java.net is 404.
Re: Usig Images from the web in Java
Woops wrong thread :confused:
Re: Usig Images from the web in Java
Thanks guys it was the URL. I finished the program using some other URL.