开发者

Java Graphics: Each time it repaints, i get a blackflash

开发者 https://www.devze.com 2023-02-23 04:54 出处:网络
I\'m pretty new to the java draw functions, but I have a sample histogram that I build. on button click, i have it rebuilding the histogram with random values. However, every time i hit the button to

I'm pretty new to the java draw functions, but I have a sample histogram that I build. on button click, i have it rebuilding the histogram with random values. However, every time i hit the button to repaint, i get a black flash before it redraws. I remember hearing this was pretty common and the fix ha开发者_运维百科d something to do with buffering. Any advice?


The first thing you do when you draw is clear your canvas. The flash you see is the blank canvas as things get drawn. If you were to slow it down fast enough, you would see each thing appear on the screen, one at a time.

You can get around this by what's called double buffering.

You paint your screen to an off-screen image. Then you paint your image to the screen all at once.


Swing is double buffered by default.

Read the section from the Swing tutorial on Custom Painting for working examples.

0

精彩评论

暂无评论...
验证码 换一张
取 消