Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double Buffering Question ? HELP ?

 
David Donovan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the following code ( incomplete ) I'm looking for someone to explain this to me so I can understand how this all ties together. I'm having a hard time making the connection between the offScreenImage and the offScreenGraphics ...
<BR>
Image offScreenImage;
Graphics offScreenGraphics;
public void init() {
offScreenImage = createImage(getSize().width,getSize().height);
offScreenGraphics = offScreenImage.getGraphics();
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
offScreenGraphics.setColor(getBackground());
offScreenGraphics.fillRect(0,0,getSize().width,getSize().height);
offScreenGraphics.setColor(Color.black);
offScreenGraphics.drawString("Kangaroo:,20,50);
g.drawImage(offScreenImage,0,0,this);
}
I'm having a hard time understanding the drawing of the offScreenImage , when it appears that we are drawing to the offScreenGraphics instead.. ?!? Can someone explain this to me and hopefully clear this up ?
Thanks in Advance.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when u use the method getGraphics() on an image you are getting a Grphihcs object that draws the image to the memory (rather than the screen).
then using that graphics object u draw to the memory whatever u want (in this case a string and a rectangle).
after completing the drawing of the image to the memory buffer, you then draw what u made to the screen itself using the "real" Graphics object.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
The article Double-Buffer Applet from Earthweb explains well how double-buffering works.
Good Luck,
-Dirk Schreckmann
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic