JApplet – super.paint(); 导致闪烁

我现在正在写一个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); } 

不要使用绘画,也不要直接在JApplet中绘制。 而是在JPanel的paintComponent方法中绘制并调用super.paintComponent(g)作为该方法的第一行。 将JPanel添加到JApplet的contentPane以允许applet显示它。

编辑1
此外,您不能使用paintComponent,因为这会完全不同。 再次使用paintComponent,但仅限于从JComponent派生的组件,例如JPanel(或JComponent本身)。

编辑2还总是将@Override放在paintComponent方法之上,以确保您实际上覆盖了super方法。