Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Double Buffering Question ? HELP ?

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 ...
Image offScreenImage;
Graphics offScreenGraphics;
public void init() {
offScreenImage = createImage(getSize().width,getSize().height);
offScreenGraphics = offScreenImage.getGraphics();
public void update(Graphics g) {
public void paint(Graphics g) {
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.
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.
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The article Double-Buffer Applet from Earthweb explains well how double-buffering works.
Good Luck,
-Dirk Schreckmann
Everybody! Do the Funky Monkey! Like this tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic