// Shows Double buffering so no image flickering! import java.applet.Applet; import java.awt.*; public class Flicker2 extends TerribleFlicker { int nextx; int nexty; Graphics og; Image offScrImg; void cliptoaffectedarea (Graphics g, int oldx, int oldy, int newx, int newy, int width, int height) { int x = Math.min(oldx, newx); int y = Math.min(oldy, newy); int w = ( Math.max(oldx, newx) + width) - x; int h = ( Math.max(oldy, newy) + height) - y; g.clipRect(x,y,w,h); } // update public void update( Graphics g ) { if (offScrImg == null) offScrImg = createImage(size().width, size().height); og = offScrImg.getGraphics(); int lastx = currentx; int lasty = currenty; currentx = nextx; currenty = nexty; cliptoaffectedarea (og, lastx, lasty, currentx, currenty, imgWidth, imgHeight); cliptoaffectedarea (g, lastx, lasty, currentx, currenty, imgWidth, imgHeight); paint(og); g.drawImage(offScrImg, 0, 0, this); og.dispose(); } public boolean mouseDrag (Event e, int x, int y) { nextx = x; nexty = y; repaint(); return true; } }