JInternalFrame 相机图像重绘问题

JInternalFrame camera image repaint issue

我使用 JInternalFrame 查看相机图像,我得到了图像,但是它 flashes/blinks 非常频繁,所以我几乎看不到图像。我扩展了 JFrame 而不是 JInternalFrame,一切正常。也许 JInternalFrame 的工作方式与 JFrame 不同,但我无法找出更新的问题。

public class CameraView extends JInternalFrame{

  private JPanel contentPane;

  VideoCap videoCapture = new VideoCap();

public CameraView(){
    setSize(400, 400);

    setLocation(100, 100);

    contentPane = new JPanel();
    setContentPane(contentPane);
    contentPane.setLayout(null);
    new MyThread().start();
}

    @Override
    public void paint(Graphics g){
        g = contentPane.getGraphics();
        g.drawImage(videoCapture.getOneFrame(), 0, 0, this);
    }


    class MyThread extends Thread{
        @Override
        public void run() {
            for (;;){
                repaint();
                try { Thread.sleep(30);
                } catch (InterruptedException e) {    }
            }  
        } 
    }

}

你必须删除

g = contentPane.getGraphics();

contentPane.setLayout(null);