imgv=createImage(x,y);gv=imgv.getGraphics();
gv.drawline()用这种方法--创建双缓冲。

解决方案 »

  1.   

    import java.awt.*;
    public class DoubleBufferPanel extends Panel{
        Image offscreen;
        public void invalidate(){
            super.invalidate();
            offscreen=null;
        }
        
        punlic void update(Graphics g){
          paint (g);
        }    public void paint (Graphics g){
          if(offscreen==null){
              offsrceen=createImage(getSize().width,
                                      getSize().height);
          }
          Graphics og=offscreen.getGraphics();
          og.setClip(0,0,getSize().width,getSize().height);
          super.paint(og);
          g.drawImage(offscreen,0,0,null);
          og.dispose();
        }
    }
      

  2.   

    谢谢两位,给分,但效果没有变,拖动的时候还闪:(
    在mouseDragged方法里应该怎样刷新线条?直接drawline两次还是repaint??
      

  3.   

    你可以创建一个新的线程,重写run的方法,将repaint()的方法加到其中去。
    试试,我们游戏都这样实现。