好的,我终于解决了。
无需每次都在
paint(Graphics g)-method 中重绘它,而是需要缓冲输出并仅重绘该图像(我有点希望Java像Obj-
C一样已经这样做了)。
public BufferedImage buffer;public void redraw() { buffer = new BufferedImage( 200, // height 300, // width BufferedImage.TYPE_4BYTE_ABGR); // ABGR = RGBA, 4-byte (r, g, b, a) per pixel Graphics g = buffer.getGraphics(); // do your drawing here if (this.getGraphics()) { // 'this' is already shown, so it needs a redraw this.paint(this.getGraphics()); // little hack }}public void update(Graphics g) { this.paint(g);}public void paint(Graphics g) { g.drawImage(buffer, 0, 0, this);}现在,当您最小化窗口并再次最大化它时,画作仍然存在。只是,窗口现在闪烁了0.1秒左右,但我并不在乎。



