【发布时间】:2011-10-23 17:00:24
【问题描述】:
我现在正在编写一个 JApplet,每当我调用 super.paint() 时,applet 都会闪烁。 我正在使用双缓冲(绘制到图像,然后渲染该图像),但我认为 super.paint() 正在清除屏幕或其他东西,破坏了我的双缓冲。
我知道我应该使用paintComponents(),但由于某种原因,当我调用“currentScreen.Draw(g)”时,它不会显示屏幕的绘制。
谁能帮我解决这个问题?
public void paint(Graphics g)
{
super.paint(g);//Remove this and it works, but the JApplet background color will be gone, and everything will be white.
currentScreen.Draw(g);
}
画面绘制方法
public void Draw(Graphics g)
{
if(buffer != null)
g.drawImage(buffer, 150, 0, null);
//g.drawString(drawstring, x, y);
}
【问题讨论】:
-
不要使用双缓冲,除非你真的必须这样做。默认情况下,JPanels 已经是双缓冲的。另外,是的,您应该使用paintComponents()。
-
@iAndrOidOs:paintComponents 是一种完全不同且不合适的使用方法。
paintComponent是 OP 应该使用的。
标签: java swing paint flicker japplet