Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

draw an image

Status
Not open for further replies.

stonee74

Technical User
Nov 12, 2001
49
CH
hey there,
It's a simple beginner question:
why is there no image on my panel?
I can draw and so on, but it displays no pic, why?
any help is greatly appreciated!
stonee

public class Frame0001 extends JFrame {

public Frame0001() {

}
public static void main(String[] args) {
Frame0001 frame0001 = new Frame0001();
frame0001.setSize(200,200);
frame0001.show();
}

public void paint (Graphics g)
{
Image img;
img = getToolkit().createImage("Image40.gif");
g.drawImage(img,100,100,null);
}

}
 
ive modified ur code so that it works. the problem might b bcoz u used createImage instead of getImage.

public class myframe extends Frame {
Image img;
public myframe() {
img = getToolkit().getImage("image.gif");
//setSize(img.getWidth(null), img.getHeight(null));
setSize(200,200);
show();
}
public static void main(String[] args) {
myframe frame = new myframe();

}

public void paint (Graphics g)
{
g.drawImage(img,100,100,this);
}
} LOL A ship is safe in the harbour, but that's not what it is meant for!!! LOL
 
under setSize
try adding setVisible(true) Thanks
Erik Butler
2000 MCSE
erikbutler@centurytel.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top