Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Usig Images from the web in Java

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default 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.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Usig Images from the web in Java

    Are you sure that the url is correct? Have you typed it into a browser?
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Usig Images from the web in Java

    As a nooby java person, i will just say this: duke.dev.java.net is 404.

  6. #6
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Usig Images from the web in Java

    Woops wrong thread
    Last edited by 12sea21; August 28th, 2011 at 01:51 AM.

  7. #7
    Junior Member
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Usig Images from the web in Java

    Thanks guys it was the URL. I finished the program using some other URL.

Similar Threads

  1. Java: Links, images, font and divisions with HTML / CSS
    By Cyloc in forum AWT / Java Swing
    Replies: 3
    Last Post: August 2nd, 2011, 12:54 PM
  2. Replies: 5
    Last Post: June 10th, 2010, 10:19 AM
  3. Loading in images
    By eXcellion in forum Java Theory & Questions
    Replies: 3
    Last Post: January 17th, 2010, 12:13 PM
  4. Images not going in email
    By anjali09s in forum Java SE APIs
    Replies: 3
    Last Post: August 2nd, 2009, 06:06 PM
  5. What are the best way of placing images in GUI?
    By Ciwan in forum AWT / Java Swing
    Replies: 5
    Last Post: February 26th, 2009, 05:19 PM

Tags for this Thread