Double Buffering "1.1 Style"

Could someone explain to me why when I try to double buffer a generated Image it return null? Heres a code snippet:

class Can ectends Canvas

{

Image offscr;

Graphics og;

public Can()

{

offscr = createImage(500,500);

og = offscr.getGraphics();

}

public void paint(Graphics g)

{

og.drawRect(1,1,100,100);

g.drawImage(offscr,10,10,this);

}

}

This is a revised version of course, I also had some Thread work and an update method. I had this working just fine with a BufferedImage in the appletviewer but

Older browser don't support it and I don't want to make people downlod plug-ins. I have seen the exact cod listed above on-line on many pages but for some reason it just keeps returning me a null Image. I am using

jdk-1.3 and Redhat Linux 6.1.

Thanks for any comments

Ian

[921 byte] By [IanMechura] at [2007-9-26 2:00:35]
# 1

createImage returns null as long as the component hasn't got a visual representation. A solution is moving the code

offscr = createImage(500,500);

og = offscr.getGraphics();

to the paint method...

if (offscr == null) {

offscr = createImage(500,500);

og = offscr.getGraphics();

}

jsalonen at 2007-6-29 8:39:55 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
Thanks jsalonen, I gave you the duke dollars, sorry about last timewith security exceptions you helped me with I didnt know that I had to award them my-self.Ian
IanMechura at 2007-6-29 8:39:55 > top of Java-index,Archived Forums,New To Java Technology Archive...