Displaying and Image
807598Aug 13 2006 — edited Aug 14 2006I'm having trouble displaying an image with this code. What's sad is that I figured it out at 3 am yesterday but then overwrote the file to expand the example. I don't remember what I did to make it workk. I only remember adding a line of code in the constructor over 'this.setVisible (true)"...but I can't remember what I did...argh!
In any case, the .gif is in the same location as the java file...The image just does not display and I think it's something simple that I'm missing.
Any help is GREATLY appreciated.
[code ]class NewFrame extends Frame
{
private Image image;
public NewFrame (int width, int height)
{
this.setTitle ("Display image example");
this.setResizable (true);
this.setBackground (Color.cyan);
this.setSize (width, height);
this.setVisible (true);
}
public void paint (Graphics g)
{
Toolkit tk = Toolkit.getDefaultToolkit ();
image = tk.getImage ("Bike.gif");
g.drawImage (image, 0, 0, this);
}
}
public class Test {
public static void main (String[] args)
{
new NewFrame (300, 200);
}
}