doublebufferpanel.java
来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 50 行
JAVA
50 行
/*
* @(#)DoubleBufferPanel.java 1.1 98/07/18
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
*
*/
package actual;
import java.awt.*;
import java.applet.*;
public class DoubleBufferPanel extends Panel {
Image offscreen;
/**
* null out the offscreen buffer as part of invalidation
*/
public void invalidate() {
super.invalidate();
offscreen = null;
}
/**
* override update to *not* erase the background before painting
*/
public void update(Graphics g) {
paint(g);
}
/**
* paint children into an offscreen buffer, then blast entire image
* at once.
*/
public void paint(Graphics g) {
if(offscreen == null) {
offscreen = 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();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?