File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double Buffering Problem

 
Martin vanPutten
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing doublebuffers by default. Have you considered it?
 
Martin vanPutten
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just told how to double buffer... I don't know what swing double buffers are.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know about Swing?
 
Martin vanPutten
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no. i'm bad with knowing what exactly with what things do.
 
Martin vanPutten
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is it possible to fix my problem with what I have now?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are erase a portion of the screen using clearRect
 
Martin vanPutten
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic