不断重新粉刷时画布闪烁 [英] Canvas blinks when constantly repainting

查看:167
本文介绍了不断重新粉刷时画布闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含 java.awt.Canvas 的应用,以显示一系列连接节点,如图中所示。编辑时,最后一个点用 java.awt.geom.Line2D 连接到鼠标光标,这样每次用户移动鼠标时都必须重新绘制它,这会导致在屏幕上真的令人作呕 - 闪现效果。

I'm making an app which contains a java.awt.Canvas to display a sequence of conected nodes like in a graph. while editing, the last dot is conected to the mouse cursor with a java.awt.geom.Line2D so that it must be repainted everytime the user moves the mouse, and it causes a really disgusting -flashy- effect on screen.

之前我做过这个,我知道解决方案很简单,不需要真正的硬代码,但是乱用 paint(g)重绘(g)更新(g) 方法,尽管如此,我无法解决它,希望有人可以帮助我!

I did this once before, and I know the solution was so easy and didn't need a really hard code, but to mess around with paint(g), repaint(g) and update(g) methods, despite it, I cannot manage to solve it and hope someone can help me!

提前多多谢意!! :)

Lots of thanks in advance!! :)

推荐答案

你需要做双缓冲才能摆脱闪烁。如果你谷歌的话可以加载一些例子。

You need to do Double Buffering to get rid of the flickering. Loads of examples if you google for it.

找到一个以前的问题有更多信息。
这是另一个示例

Found a previous question that has more info. Here is another example.

这篇关于不断重新粉刷时画布闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆