双缓存

1 private Image offImage = new BufferedImage(800, 700, BufferedImage.TYPE_INT_RGB);//在内存中new一张图片出来
 1 public void paint(Graphics g) {
 2         Graphics offG = offImage.getGraphics();//得到内存图片的画笔
 3         super.paint(offG);
 4         for (Shape shape : shapes) {
 5             if (shape != null) {
 6                 shape.draw(offG);//把图形画到内存图片上
 7             }
 8         }
 9         g.drawImage(offImage,0,0, null);//把内存中的图片画到屏幕上
10     }

 

posted @ 2014-11-05 21:24  FJ凉风  阅读(144)  评论(0编辑  收藏  举报