以下是对JFrame或继承JFrame的游戏窗口进行重载。
private Image iBuffer;
private Graphics gBuffer;
public void paint(Graphics g) {
g.drawRect(0, 0, 100, 100);
}
public void update(Graphics g) {
if (iBuffer == null) {
iBuffer = createImage(this.getSize().width,
this.getSize().height);
gBuffer = iBuffer.getGraphics();
}
gBuffer.setColor(getBackground());
gBuffer.fillRect(0, 0, this.getSize().width, this.getSize().height);
paint(gBuffer);
g.drawImage(iBuffer, 0, 0, this);
}