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 3783230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:11:42+00:00 2026-05-19T11:11:42+00:00

Hello I’m writing a small game and it’s nearly finished, the only thing that

  • 0

Hello I’m writing a small game and it’s nearly finished, the only thing that doesn’t work is the ImageBuffer. Every 10 miliseconds I call the method repaint(). My paint() method is as follows:

private Graphics2D g2D;

public void paint (Graphics g) {
    BufferedImage bimage = ((Graphics2D)g).getDeviceConfiguration().createCompatibleImage(700, 600, Transparency.OPAQUE);
    g2D = bimage.createGraphics();
    g2D.setFont(font);        
    for(Wall wall: walls){
        wall.paint(g2D);
    }
    g2D.setColor(Color.orange);
    paddle.paint(g2D);
    g2D.drawString(score + "", 150,50);
    g2D.drawString("record: "+topscore  , 350,50);
    g2D.setColor(Color.red);
    ball.paint(g2D);
    g.drawImage(bimage,0,0,this);
}

But this doesn’t seem to remove the flickering. I think somehow the screen is cleared before the bufferedimage starts being painted.
Can anyone help me with solving this problem?
thanks!

  • 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-05-19T11:11:43+00:00Added an answer on May 19, 2026 at 11:11 am

    You should extend JComponent instead of Canvas, depending on if you are using Swing rather than AWT. Doing this gives you a nice lightweight component and doesn’t need you to implement double-buffering support. Then, in your overridden paintComponent(..) draw your image with the provided Graphics object.

    On the subject of the original code, creating a new compatible image every single time in paint is blooming horrible (it’s a very expensive operation that uses large bytebuffers — you’ll get frequent GC pauses). If you really want double buffering in AWT (which will give you flickering when resizing but should be okay in an applet), you should look into BufferStrategy.

    Edit: changed Component to JComponent, oops 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello for my app I need to save a record that the user type,
Hello I want to get Accurate location so that i have used following link
Hello guys i have been using JavaFx scene builder to build a gui that
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello I want to know how to highlight all Words that is inputted in
Hello does any one know that setting I need to ON for connect to
Hello guys I need to pass a string array over to a setter that
Hello , I am using arshaw fullcalendar v1.5.2 (only month view ) for property
Hello i have a TextField on my scene. It haves only digits, user input
hello I build application with google maps api , the apk work fine till

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.