Hi, what am i missing? Assume the following code for displaying an Image in a frame. <pre> import java.awt.*; public class ImageFrame extends FrameWithClose { Image img; public ImageFrame() { img = Toolkit.getDefaultToolkit().getImage("c:\\img.jpg"); } public void paint(Graphics g) { g.drawImage(img, 0, 0, this); } public static void main(String [] args) { ImageFrame f = new ImageFrame(); f.setSize(640, 480); f.repaint(); f.setVisible(true); } } </pre> But there is nothing displayed. What I am doing wrong. Thanks for help Heli
img.jpg doesn't really exist where you say it does... Java will try to load your image, but if it's not there, a null image reference will be used with no complaints.
Your image is small and is being drawn underneath the title bar of the window... you can fix this by either changing the x,y coordinates in your paint method, or by painting the image on a Panel that is then placed in the Frame...
-Nate
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Helmut Lerch
Ranch Hand
Joined: Feb 11, 2001
Posts: 48
posted
0
Thanks for answering.
Originally posted by Nathan Pruett: From what I see two things could be wrong...
img.jpg doesn't really exist where you say it does... Java will try to load your image, but if it's not there, a null image reference will be used with no complaints.
-Nate
I thought there will be sure some Exception if this happens. Again thanks Heli