Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:25:36+00:00 2026-06-14T18:25:36+00:00

I found this code of double buffering on internet but it has no explaination.

  • 0

I found this code of double buffering on internet but it has no explaination. I am a little confused in this code.

  • Why is the Image “i” used? What is its use if it is to be used once?

  • Why are we assigning changing color to Foreground color,when we already have set color?

  • What is g.drawImage() method doing?

Here is the code:

public void update(Graphics g)
{
    if(i==null)
    {
        i=createImage(getWidth(), getHeight());
        graph=i.getGraphics();
    }

    graph.setColor(getBackground());
    graph.fillRect(0, 0, getWidth(),getHeight());
    graph.setColor(getForeground());

    paint(graph);

    g.drawImage(i,0,0,this);
  }

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:25:38+00:00Added an answer on June 14, 2026 at 6:25 pm

    The basic idea of Double Buffering is to create the image off screen then display it all at once.

    Double Buffering

    From the java tutorials found here

    The code you have there first creates an image on first way through to be your “Back Buffer” with this bit, i is likely a field such as

     private Image i;
     private Graphics graph;
    
     if(i==null)
    {
        i=createImage(getWidth(), getHeight());
        graph=i.getGraphics();
    }
    

    Then Paints the background color onto the image with this

    graph.setColor(getBackground());
    graph.fillRect(0, 0, getWidth(),getHeight());
    

    Then sets the front ready for drawing.

    graph.setColor(getForeground());
    paint(graph); /draws
    

    Finally drawing the back Buffer over to the primary surface.

    g.drawImage(i,0,0,this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this code in the internet and I modified it for my use,
I found the below code here: How to use double buffering inside a thread
Found this code that breaks out CSV fields if contains double-quotes But I don't
I found this line of code in some code I'm analyzing: Mintau = (double*)
I found this code for alphanumeric check (Letters, numbers, spaces or underscores) but I
I found this code from here: http://www.cssportal.com/form-elements/text-box.htm But the problem is you can still
I found this code online as a template for doing a string to float/int/double
hello i have found this code on windows documentation but i don't get what
I found myself staring at code that looks similar to this: private double? _foo;
My code can also be found here . This code would work (but there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.