Cannot see image with drawImage()

I have been trying to get an image to display to a JFrame, but have been unable to do so, I have read a couple of tutorials and quite a few forum posts, but none of them have been able to help me to understand what I am doing wrong so I am hoping that someone here can help me. Im not sure exactly what people will and will not want from my code so I am posting the entire class, I can provide other classes if requested, following is the code:
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class myWindow extends JFrame
     //Lets set up the basic thread stuff
     private final static int FONT_SIZE = 24;
     //lets create all those properties shall we
     private Image bgImage = null;
     private Image opaqueImage = null;
     private Image transparentImage = null;
     private Image translucentImage = null;
     private Image antiAliasedImage = null;
     private boolean imagesLoaded;
     * This class sets the bunch of images into image objects. It then sets the
     * imagesLoaded to true and tells the window to repaint itself with them.
     public void loadImages()
          //lets put all those images into Image objects shall we.
          bgImage = loadImage("images/background.jpg");
          opaqueImage = loadImage("images/opaque.png");
          transparentImage = loadImage("images/transparent.png");
          translucentImage = loadImage("images/translucent.png");
          antiAliasedImage = loadImage("images/antialiased.png");
          //The images have been loaded
          imagesLoaded = true;
     * Returns a boolean for the condition of the pictures, loaded or unloaded.
     * @return The imagesLoaded value
     public boolean getImagesLoaded()
          return imagesLoaded;
     * Sets the imagesLoaded attribute of the myWindow object
     * @param isLoaded This will set the image loaded to the passed boolean.
     public void setImagesLoaded(boolean isLoaded)
          imagesLoaded = isLoaded;
     * Takes the location of an image and places it into an Image object.
     * @param fileName This is the location of the image to be set into an Image
     * object
     * @return Description of the Return Value
     private Image loadImage(String fileName)
          //This will put the passed string into an Image and returning it.
          return new ImageIcon(fileName).getImage();
     * This will place all the pictures onto the screen
     * @param g This is the graphics that we are using
     public void paint(Graphics g)
          //Lets get all the text to be anti-aliased
          if (g instanceof Graphics2D)
               Graphics2D g2 = (Graphics2D) g;
               g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
          //Lets draw some images
          if (imagesLoaded == true)
               this.setBackground(Color.orange);
               //first we set the background
               g.drawImage(bgImage, 0, 0, null);
               //Next we thow on a bunch of images
               placeImage(g, opaqueImage, 0, 0, "Opaque");
               placeImage(g, transparentImage, 320, 0, "Transparent");
               placeImage(g, translucentImage, 0, 300, "Translucent");
               placeImage(g, antiAliasedImage, 320, 300, "Anti-Aliased");
          else
               this.setBackground(Color.gray);
               //Lets let the user know that we are loading the images.
               g.drawString("Loading...", 5, FONT_SIZE);
     * This will place an image onto the JFrame object.
     * @param g This is the Graphics that is being used
     * @param image This is the image that you want to draw
     * @param x This is the width placement
     * @param y This is the height placement
     * @param caption This is waht it has to say about your image.
     private void placeImage(Graphics g, Image image, int x, int y, String caption)
          //lets put the passed image onto the screen.
          g.drawImage(image, x, y, null);
          //Now lets put down the caption for the picture.
          g.drawString(caption, x + 5, y + FONT_SIZE + image.getHeight(null));
}

import java.awt.*;
import javax.swing.*;
public class MWTest extends JPanel
    //Lets set up the basic thread stuff
    private final static int FONT_SIZE = 24;
    //lets create all those properties shall we
    private Image bgImage = null;
    private Image opaqueImage = null;
    private Image transparentImage = null;
    private Image translucentImage = null;
    private Image antiAliasedImage = null;
    private boolean imagesLoaded;
    public MWTest()
        this.setBackground(Color.orange);
        imagesLoaded = true;
        loadImages();
     * This class sets the bunch of images into image objects. It then sets the
     * imagesLoaded to true and tells the window to repaint itself with them.
    public void loadImages()
        //lets put all those images into Image objects shall we.
        bgImage          = loadImage("images/background.jpg");
        opaqueImage      = loadImage("images/opaque.png");
        transparentImage = loadImage("images/transparent.png");
        translucentImage = loadImage("images/translucent.png");
        antiAliasedImage = loadImage("images/antialiased.png");
     * Returns a boolean for the condition of the pictures, loaded or unloaded.
     * @return The imagesLoaded value
    public boolean getImagesLoaded()
        return imagesLoaded;
     * Sets the imagesLoaded attribute of the myWindow object
     * @param isLoaded This will set the image loaded to the passed boolean.
    public void setImagesLoaded(boolean isLoaded)
        imagesLoaded = isLoaded;
     * Takes the location of an image and places it into an Image object.
     * @param fileName This is the location of the image to be set into an Image
     * object
     * @return Description of the Return Value
    private Image loadImage(String fileName)
        //This will put the passed string into an Image and returning it.
        //return new ImageIcon(fileName).getImage();
        // one problem with the single line of code is that you do not
        // get any feedback for load failure
        ImageIcon icon = new ImageIcon(fileName);
        Image image = icon.getImage();
        int status = icon.getImageLoadStatus();
        if(status == MediaTracker.ABORTED || status == MediaTracker.ERRORED)
            System.out.println("image loading failed for " + fileName);
            imagesLoaded = false;
        return image;
     * This will place all the pictures onto the screen
     * @param g This is the graphics that we are using
    public void paintComponent(Graphics g)
        super.paintComponent(g);
        //Lets get all the text to be anti-aliased
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //Lets draw some images
        if (imagesLoaded)
            //first we set the background
            g.drawImage(bgImage, 0, 0, null);
            //Next we thow on a bunch of images
            placeImage(g, opaqueImage, 0, 0, "Opaque");
            placeImage(g, transparentImage, 320, 0, "Transparent");
            placeImage(g, translucentImage, 0, 300, "Translucent");
            placeImage(g, antiAliasedImage, 320, 300, "Anti-Aliased");
        else
            //Lets let the user know that we failed to load the images.
            g2.setPaint(Color.gray);
            g2.fillRect(0,0,getWidth(),getHeight());
            g2.setPaint(Color.red);
            g2.setFont(g2.getFont().deriveFont((float)FONT_SIZE));
            g.drawString("Loading failed...", 25, 100);
     * This will place an image onto the JFrame object.
     * @param g This is the Graphics that is being used
     * @param image This is the image that you want to draw
     * @param x This is the width placement
     * @param y This is the height placement
     * @param caption This is waht it has to say about your image.
    private void placeImage(Graphics g, Image image, int x, int y, String caption)
        //lets put the passed image onto the screen.
        g.drawImage(image, x, y, null);
        //Now lets put down the caption for the picture.
        g.drawString(caption, x + 5, y + FONT_SIZE + image.getHeight(null));
    public static void main(String[] args)
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new MWTest());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • Azure Storage Blob error - AnonymousClientOtherError and AnonymousNetworkError (why cannot see images)

    I have an mobile app and I put images in Azure Storage Blob. when tested by several of our own people (on test and beta), it is all good.
    But when we released it to beta and had hundreds (maybe above one thousand) of users to use, lots of them report that they cannot see images. It happens on their iPhones and also on many different brands of Android phones. Sometimes, for the same image,
    on one phone it is good, but on another it doesn't show.
    When I check blob log, I saw a lot of errors, mainly these two:
    AnonymousClientOtherError; 304
    "Anonymous request that failed as expected, most commonly a request that failed a specified precondition. The total number of anonymous requests that failed precondition checks (like If- Modified etc.) for GET requests. Examples: Conditional GET requests
    that fail the check."  (From Microsoft)
    AnonymousNetworkError; 200
    "The most common cause of this error is a client disconnecting before a timeout expires in the storage service. You should investigate the code in your client to understand why and when the client disconnects from the storage service. You can also use
    Wireshark, Microsoft Message Analyzer, or Tcping to investigate network connectivity issues from the client. " (From Microsoft) - a question here, this is an error, but why it is 200?
    I wonder if these are the reasons that caused my problem?
    For the first one, from my understanding, it is not actually an error, it just says that the version client cached is the same as server version. But when my client side sees this response, it thinks it is an error and throw an exception and thus no image
    is shown? (I actually outsourced my client side, so I can only guess). I later tested with my browser to access these images and found that if I refresh the browser with the same URL of the image, I saw error 304 on the log but I still see the image. So I
    guess this is not actually a reason for my problem.
    For the second one, is it because my client side's timeout is shorter than the server side's timeout? But is the timeout a connection timeout or a socket timeout? what are the default values on client side and on Azure Blob? Or is it because the network
    is not good? My Azure server is located in East Asia (Hongkong), but my users are in mainland China. I wonder if that could cause problem? But when a few users tested in China it is all good.
    Many of the images are actually very small,  just one to two hundred k. Some are just 11k.
    I cannot figure out what is the reason...

    Hi,
    Does any people encounter this error when they access the small picture, if this issue is only caused by large picture, please try to improve the timeout, you can also monitor your storage account from the Azure Management Portal, this may be help us
    to find out the detailed error information. see more at:
    http://azure.microsoft.com/en-gb/documentation/articles/storage-monitor-storage-account/, hope it helps.
    Regards

  • Cannot see Cookies with new update of firefox. I recently updated firefox, but when I look on the PRIVACY window, where websites store cookies, I am no longer a

    Cannot see Cookies with new update of firefox.<br />
    I recently updated firefox, but when I look on the PRIVACY window, where<br />
    websites store cookies, I am no longer able to see any cookies that<br />
    are being stored, and I am not able to delete the cookies as soon as I leave<br />
    their site, as I had been doing for a long time prior to updating.<br />
    So I am wondering where the heck are the cookies being stored now, with the<br />
    new update? I like to be able to delete their cookies immediately, and<br />
    I also wonder why firefox does not make it much easier for us to see<br />
    all the cookies and delete them with one click, instead of having to <br />
    use the &lt;&lt;TOOLS&lt;&lt;OPTIONS&lt;&lt;PRIVACY way of looking at and deleting cookies.<br />
    The option to delete the cookies when firefox closes is not as efficient<br />
    and I will get tracked until I close firefox, and I prefer to not be tracked<br />
    so I like to just delete their cookies as soon as I am no longer using their<br />
    site anymore.

    (my question was not fully showing so I added this here)
    way of looking at and deleting cookies.
    The option to delete the cookies when firefox closes is not as efficient
    and I will get tracked until I close firefox, and I prefer to not be tracked
    so I like to just delete their cookies as soon as I am no longer using their
    site anymore. So I need to know how to make the cookies visible again, so I can immediately delete them. thank you

  • I cannot see toolbar with favourites, file etc so i cannot join any pages to my favourites. Where it's gone...?

    I cannot see toolbar with favourites, file etc so i cannot join any pages to my favourites. Where it's gone...?

    Firefox 3.6+ versions have a feature to allow the user to hide the Menu bar.
    Hit the '''Alt''' key to temporarily show the Menu bar, then open View > Toolbars and select Menu bar, so it has a check-mark. <br />
    The F10 can also be used on most PC's to temporarily reveal the Menu bar.
    https://support.mozilla.com/en-US/kb/Menu+bar+is+missing

  • I have a MacBook Pro Retina (2,3 GHz Intel Core i7 - 8 GB 1600 MHz DDR3 - Intel HD Graphics 4000 1024 MB). I use KompoZer for my website, but after installing OS X Yosemite it doesn't work right (I cannot see images in the website).

    I have a MacBook Pro Retina (2,3 GHz Intel Core i7 - 8 GB 1600 MHz DDR3 - Intel HD Graphics 4000 1024 MB). I use KompoZer for my website, but after installing OS X Yosemite it doesn't work right (I cannot see images in the website).

    It's beta open source software so I'm not surprised. It does't look to be too active a project, so I don't know if it will help or not but you might be maybe better off posting a bug report on their Sourceforge page here: http://sourceforge.net/projects/kompozer/

  • Hello! I have configured my Wireless network to support bonjour protocol. When I support mDNS in the same Vlan I can see the Apple TV with my iPhone, but I cannot see it with my iPad.

    Hello! I have configured my Wireless network to support bonjour protocol. When I support mDNS in the same Vlan I can see the Apple TV with my iPhone, but I cannot see it with my iPad. Someone know if there is any different in the Bonjour protocol between the iPhone and the iPad???
    It is like if the iPad changes the process at some point...
    Thank you!

    You don't need to configure anything specific for it to work unless you had some special filtering in place already.
    What do you mean specificly by can not "see" it with your iPad?

  • When trying to crop an image in Lightroom Develop I get a blue overlay screen and cannot see image

    When trying to crop an image in Lightroom Develop I get a blue overlay screen and cannot see image. I have uninstalled and reinstalled but same result. How can I get this reset to show selected image and crop handles?

    That has fixed it, all working fine now, thanks.

  • CANNOT SEE IMAGES INCERTAIN WEBSITES

    Hi,
    I cannot see some of the images in this website. Please help.
    thanks

    If images are missing then check that you aren't blocking images from some domains.
    *Check the permissions for the domain in the current tab in "Tools > Page Info > Permissions"
    *Check that images are enabled: Tools > Options > Content: [X] Load images automatically
    *Check the exceptions in "Tools > Options > Content: Load Images > Exceptions"
    *Check the "Tools > Page Info > Media" tab for blocked images (scroll through all the images with the cursor Down key).
    If an image in the list is grayed and there is a check-mark in the box "<i>Block Images from...</i>" then remove that mark to unblock the images from that domain.
    There are also extensions (Tools > Add-ons > Extensions) and security software (firewall, anti-virus) that can block images.
    See also:
    *http://kb.mozillazine.org/Images_or_animations_do_not_load

  • Cannot see image when use sendRedirect

    HI,
    I have a little servlet that try redirct to external link
    response.sendRedirect("http://wap.yahoo.com/");
    I get the yahoo page but cannot see the image,
    I look on the source of the page I got
    <img src="/images/yahooicon.wbmp" alt="Yahoo!"/>
    I cannot chage yahoo page :-(
    any suggestions ?
    Thanks

    Hi,
    The site http://wap.yahoo.com/ does not contain HTML. It contains WML scriptlets. It will not work if you are using a Internet browser. You need to have a Mobile browser to see the content properly.
    I tried to redirect to http://www.yahoo.com/ and I am able to see the images in this site properly.
    The problem is not with Yahoo site but the Browser you are trying to access it with. :D
    Thanks and regards,
    Pazhanikanthan. P

  • Cannot see images occassionally: "Out of memory"

    Hi,
    I love Lightroom, but have the problem that is really interfering with my work. When I look at a larger collection of images (100+), every now and then the image area will be greyed out, and it will say 'Out Of Memory' in red (upside down and back to front) in the lower left corner.
    This never happens when I am looking at thumbnails in Library-mode. It does happen when I am looking one image in Library-mode, in deverloper mode, and frequently in the Slide-show mode. Interestingly enough: when an image is not visible in Library-mode, chances are it is visible in Developer-mode and Slide-show (and vice-versa).
    I use Lightroom for a lot of subtle retouching, so I can imagine the files are large. I would understand in Slide-show that the CPU simply doesn't have the time to render the image with all the alterations I apply to it -- but in Developer and Libarary-mode I can wait and wait, and the image nevr shows up. Then I go to Developer, and there it is!
    I store my images on a seperate dedicated external harddisk connected through USB 2.0. I have browsed through the forum already, and found a solution in changing the windows pageview setting. I did this, but it made no difference. The problem still occurs with the same frequency. I have not installed LR 1.1 yet; the negative reports on this forum have scared me: I really don't need my database messed up right now.
    Any suggestions you might have will be greatly appreciated!
    Rogier Bos
    Rotterdam, The Netherlands.

    Guys,
    Before I start this rant... I LOVE LIGHTROOM... but no more ADOBE, I cannot stand it anymore... sort out the OOM errors now, before I put my Lightroom CD into the shredder and then post this SHAM on every ADOBE forum I can find.
    I have experienced the out of memory error 11 times today. I am working with 30,000+ images in Lightroom 1.1 on XP, but only looking through 58 files while doing an import of 100 files I get the "OUT OF MEMORY A2" error. This looks suspiciously like another of the, now famous, debug errors used by the developers to track the 'pain' issues. I would challenge Adobe that they know EXACTLY why this happens, a limitation in the programming techniques for their chosen development platform is highlighting issues in the Windows Memory sub-system and they cannot do diddly squat about it... they are just 'attempting' to clean up memory leaks where they can, by putting markers (A2) into the code. It would seem that they are down a creek without the proverbial paddle.
    Tom Hogarty & ADOBE listen up... stabilize the memory issues stop listening to your marketing bods who are probably leaning over your shoulder as I write these words. You are going to suffer at the hands of Aperture and Capture One if you dont get your act together. I have used both of the above with little or NO errors at all.
    Tell us ADOBE why do none of your engineers or developers talk openly about OOM errors, stop silencing them... lets get a discussion going there are some very capable developers out there willing to help for FREE! Are you mad... admit the problems and get people to help... Open Standards could teach you guys a thing or two!
    Remember for everyone of of us that actually has the balls to complain, there are a 1000 who just sit and suffer not knowing what to do!
    Fix the OOM issues before you do anything else this week!! Provide an interim 1.1.x update and make people happy they bought ADOBE and above all else remember at the end of the day these people PAY your wages.
    ...Now where is my Capture One license key...
    Damon Knight
    Photographer
    London

  • CANNOT SEE EMAILS WITH EMBEDDED LINKS ON MY HTC INCREDIBLE

    I recently linked my Outlook account through a POP3 on my HTC Incredible.  For some reason I'm not able to view messages with embedded links in the body of the email or the senders signature.  For example - If someone sends me an email and they have a FB icon embeded in their signature, I'm unable to view the email.  I can see who it's coming from but cannot see the text in the body of the email.  Does anyone have any work throughs for this issue?  Thanks!

    Hello,
    Please try the troubleshooting step provided below:
    Touch the Email icon from the Home Screen.
    Touch Mail size limit option.
    Touch No limit.
    Another tool that you may find useful, is the HTC Simulator that can be found at the link below:
    HTC Incredible Simulator
    Thank you.
    KellyW@VZWSupport

  • Cannot see image

    No matter what I try I cannot see the 300x300 jpg I uploaded and described in my .xml file.
    The xml is here:
    http://www2.iteams.org/~meyerss/blog/wp-content/movies/mensbfast.xml
    Could someone tell me what I'm doing wrong?
    Dual 2.5G   Mac OS X (10.4.5)  

    Hi Simon,
    When you use itunes tags, you have to add some extra code to your feed. From the tech specs here:
    http://www.apple.com/itunes/podcasts/techspecs.html
    Defining Tags with the iTunes Podcasting Namespace
    When using the iTunes tags, you must add a namespace declaration as the second line in your feed xml, like this:
    <rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
    The namespace declaration points to a document that defines the iTunes tags. Without the declaration, the tags are meaningless.

  • Cannot see backups with Time Machine and Aiport Extreme

    My MacBook Pro is backing up to to an Airport Extreme with a USB drive attached to it. The backing up seems to be working. ie time machine say's it backed up my machine.. eg at 1.57.pm today.
    When I enter time machine to try and get a backup, it's not there... it has one finder window for "Now" (1st April) and then the next one in the list is 23rd of March. SO I cannot see any of today, yesterday or another other recent backups.
    BTW, I had originally made a backup directly to the USB drive. I am not sure of the date but it could have been 23rd of March.
    Any ideas?

    Hey
    I have the exact same problem. I have just switched from direct firewire-based Time Machine backup to an external drive, to said drive now connected to my Airport Extreme. I knew that it wouldn't accept the old TM backups, so I started up: Started the initial backup wirelessly, the unplugged it, and finished it via firewire. All worked fine, and the sparseimage was recognized and so on. After it was done, I attached the drive to the AE again, and it backup up as it was supposed to 3-4 times a day.
    That was 3 days ago. But when I checked my TM yesterday, there was just the "today" window, and I couldn't browse anything. Today it's the same story. What gives?
    Now, I opened the sparseimage on the TM drive to see if the incremental backups were there, and they were all there, but somehow TM doesn't read them. Can anybody who has a working TM wireless backup tell me if TM mounts the sparseimage to when launched and unmounts it afterwards?
    TM worked great before when connected directly – never had a problem before and something tells me it's a problem with the sparseimage...Nevertheless, if it can't be fixed, I am back to friewire-based TM backup ;-<
    Message was edited by: Hedemann

  • Cannot open images with cc2014...click on open with and cc2014 is not an option

    Cannot open an image with cc2014 when right click on it in Windows 7....also cannot use photoshopCC as an external editor in ProShow producer

    Surely the Adobe forums are the place for help with Adobe applications. The fact that the problem doesn't occur on your daughter's machine suggests that it's not an issue with Mavericks but a local problem on your own machine.

  • Cannot see photos with iphoto

    I tried to backup my photos with a new drive.  I had them all on an external lacie drive that was full.  I moved the photos and now iphoto cannot see them.  I made a copy on my hard drive but iphoto still cannot seem them.  I opened the package and all the photos are there, thank god.  However, I cannot get them into iphoto for browsing.  Any ideas?  I am running iphoto 08 and 10.6.8.
    Bill

    If you don't have a Preferences option under the iPhoto menu then you have a damaged iPhoto preferecne file or a damaged applicaiton.  First make a temporary, backup copy (if you don't already have a viable backup copy) of the library and try the following:
    1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your
         User/Home()/Library/ Preferences folder.
    2 - delete iPhoto's cache file, Cache.db, that is located in your
         User/Home()/Library/Caches/com.apple.iPhoto folder. 
    3 - launch iPhoto and try again.
    NOTE: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding down the Option key when launching iPhoto.  You'll also have to reset the iPhoto's various preferences.
    If that doesn't help you'll need to reinstall iPhoto. To do so you'll have to delete the current application and all files with "iPhoto" in the file name with either a .PKG or .BOM extension that reside in the HD/Library/Receipts folder and from the /var/db/receipts/  folder,
    Click to view full size
    Then install iPhoto from the disk it came on originally.

Maybe you are looking for

  • LexMark 544 duplex does not work after update 10.6.5

    Unable to Duplex print in QXP after update to 10.6.5. Quark says duplex is a PPD feature. Apple Tech support says its a PPD issue also and they have to wait until the 3rd party software (QUARK) updates PPD. ?????

  • Message error when sending to multiple recipients/contacts

    Ever since 3.0 I can't send messages to multiple recipients. I'm on Optus in Australia using a 16gb 3G. Anyone else having this problem? Any fixes?

  • Acrobat 9.0 licensing issue - "serial number is invalid"

    I bought a copy of Acrobat 9.0 standard.  Installed it on my desktop PC (no issues).  But when I installed it on my laptop, I got an error that I exceeded my number of licenses.  After talking to Adobe (twice), with them telling me that they had incr

  • Pairing my laptop to apple tv

    how to pair my laptop to apple tv

  • Adcmctl.sh very slow on R12

    Hi, adcmctl.sh command takes a lot of time to bring down the concurrent services in R12 env compared to 11i version. I can understand this if we have brought down the services when any concurrent requests are still running , but this happens even whe