Results 1 to 6 of 6
Like Tree2Likes
  • 2 Post By Norm

Thread: Why doesn't this work?

  1. #1
    mailman is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Why doesn't this work?

    So what i'm trying to do hear is quite simple. I want to take a jpg from paint and simply have it display in the applet. The code runs however the applet viewer appears blank? Please help! Here's my code:

    import java.awt.*;
    import java.applet.*;


    public class Set_up extends Applet
    {
    Image img;

    public void init()
    {
    img = getImage(getDocumentBase(), "greek-flag.jpg");
    }


    public void paint(Graphics g)
    {
    g.drawImage(img,0,0,this);
    }
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,580
    Rep Power
    25

    Default Re: Why doesn't this work?

    Your code works for me.
    Make sure the image is where the program is looking for it and spelled correctly.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,580
    Rep Power
    25

    Default Re: Why doesn't this work?

    Cross posted at Why doesn't this work?
    DarrylBurke and Fubarable like this.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Why doesn't this work?

    Thanks for the heads-up

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    mailman is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Why doesn't this work?

    Quote Originally Posted by Norm View Post
    Your code works for me.
    Make sure the image is where the program is looking for it and spelled correctly.
    is there a specific location on the computer where the file must be stored? or can it be just sitting on the desktop?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,580
    Rep Power
    25

    Default Re: Why doesn't this work?

    put it in the location returned by the getDocumentBase() method.
    To see where that is, add a println to the code to print out its value.

Similar Threads

  1. JFileChooser doesn't work as it should!
    By fioan89 in forum AWT / Swing
    Replies: 1
    Last Post: 09-13-2011, 02:06 PM
  2. Jar doesn't work
    By mad72584 in forum New To Java
    Replies: 35
    Last Post: 08-07-2011, 05:22 PM
  3. Why doesn't this HelloWorld work?
    By Josep_16 in forum Java Applets
    Replies: 3
    Last Post: 07-15-2011, 03:03 AM
  4. why this doesn't work?
    By hitesh_public in forum New To Java
    Replies: 5
    Last Post: 08-09-2010, 08:07 AM
  5. Why doesn't this work?
    By Corder10 in forum New To Java
    Replies: 1
    Last Post: 07-04-2009, 10:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •