This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Double Buffering Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Double Buffering Problem" Watch "Double Buffering Problem" New topic
Author

Double Buffering Problem

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
I decided to use double buffering to eliminate the flashing in my applet. But there is a problem. Instead of things moving slowly... everything is saved on to the screen and stays there. For example... the ball is suppose to move like any ball would... but instead it creates a line of balls that don't disappear. How can I fix this?





Live And Let Learn.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Swing doublebuffers by default. Have you considered it?


There is no emoticon for what I am feeling!
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
I was just told how to double buffer... I don't know what swing double buffers are.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Martin vanPutten:
I was just told how to double buffer... I don't know what swing double buffers are.

The sweet thing is that you don't have to know anything. It's part of the furniture. Just write the code that renders in a simple manner and if you are using Swing components, they will take care of the double buffering.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Originally posted by Martin vanPutten:
I was just told how to double buffer... I don't know what swing double buffers are.


Where are you using double buffering?

This is an example of how you use it.

Notice that the only thing you have to do to implement double buffering with Applet is override update so it only call paint, and then in paint draw on the offscreen image. After the offscreen image is finished, then display it.

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
The sweet thing is that you don't have to know anything. It's part of the furniture. Just write the code that renders in a simple manner and if you are using Swing components, they will take care of the double buffering.


I don't understand.
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
The sweet thing is that you don't have to know anything. It's part of the furniture. Just write the code that renders in a simple manner and if you are using Swing components, they will take care of the double buffering.


I don't understand.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Do you know about Swing?
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
no. i'm bad with knowing what exactly with what things do.
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
Can somebody look through my code and point out the problem... then I could look at it... and try and figure it out?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I was asking if you knew Swing because most Java programmers who have the choice prefer Swing over the AWT. From your answer, although unclear, I assume you don't know Swing. Then I can't help you. I also avoid applets, but that's a story for another time...
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
So is it possible to fix my problem with what I have now?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Martin vanPutten:
So is it possible to fix my problem with what I have now?


Yes. Digest what Keith wrote. Again, it would be simpler if you knew Swing.
Larry Eisenstein
Greenhorn

Joined: Feb 21, 2006
Posts: 14
It sounds like you are repainting the screen or background, but not the ball.

You could also try "erasing" the ball.
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
I considered erasing the graphics after they moved from there previous spots but I don't know how to go about it. Can somebody shed some light?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You are erase a portion of the screen using clearRect
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
I played with it a little. But I can't figure out how to use the clearOval to erase the previous balls?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Double Buffering Problem