[英]Canvas blinks when constantly repainting
I'm making an app which contains a java.awt.Canvas
to display a sequence of conected nodes like in a graph. 我正在创建一个包含java.awt.Canvas
的应用程序,以显示一系列连接节点,如图中所示。 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. 在编辑时,最后一个点用java.awt.geom.Line2D
连接到鼠标光标,这样每次用户移动鼠标时都必须重新绘制它,这会在屏幕上产生一种非常令人作呕的闪烁效果。
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! 之前我做过这个,我知道解决方案非常简单并且不需要真正的硬代码,但要乱涂paint(g)
, repaint(g)
和update(g)
方法,尽管如此,我不能设法解决它,希望有人能帮助我!
Lots of thanks in advance!! 非常感谢提前!! :) :)
Here is a tutorial on double buffering http://download.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html 这是一个关于双缓冲的教程http://download.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html
The idea is basically that you draw to an offscreen image, then once you are finished drawing the entire image you paint that image to the screen. 这个想法基本上是你绘制到一个屏幕外的图像,然后一旦你完成绘制整个图像,你将该图像绘制到屏幕上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.