import java.awt.*; import java.awt.event.*; class LightContainer extends Container { private Image background; protected OffBuffer buffer = new OffBuffer(this); public LightContainer(){ this(null); } public LightContainer(Image background) { setLayout (null); if (background != null) this.background = background; /* guard against component resizing */ addComponentListener(new ComponentAdapter(){ public void componentResized(ComponentEvent e){ buffer.update(); repaint(); } }); } public void update(Graphics g) { paint(g); } public void paint (Graphics g) { if (damaged(g)) buffer.blitWork(g.getClipBounds()); else { Graphics work = buffer.getWorkGraphics(); Dimension size = getSize(); paintBackground(); work.setClip (0,0,size.width, size.height); super.paint(work); buffer.blitWork(); work.dispose(); } } public void paintComponent (Component comp) { paintComponent (comp, true); } public void eraseComponent (Component comp) { eraseComponent (comp, true); } public void paintComponent (Component comp, boolean update) { Graphics work = buffer.getWorkGraphics(); Rectangle bounds = comp.getBounds(); Graphics compG; compG = work.create(bounds.x, bounds.y, bounds.width, bounds.height); comp.paint (compG); if (update) buffer.blitWork(bounds); work.dispose(); } public void eraseComponent (Component comp, boolean update) { Rectangle bounds = comp.getBounds(); buffer.blitBack(bounds); paintOverlap(comp); if (update) buffer.blitWork(bounds); } public void paintOverlap(Component comp) { Graphics work = buffer.getWorkGraphics(); Rectangle bounds = comp.getBounds(); work.setClip (bounds); comp.setVisible(false); super.paint(work); comp.setVisible(true); work.dispose(); } public void moveComponent (Component comp, Point newLoc) { Rectangle oldBounds = comp.getBounds(); eraseComponent(comp, false); comp.setLocation (newLoc); paintComponent(comp, false); buffer.blitWork(oldBounds.union(comp.getBounds())); } public boolean damaged(Graphics g) { Rectangle clip = g.getClipBounds(); Dimension size = getSize(); return ( (clip.x != 0 || clip.y != 0) || (clip.width < size.width || clip.height < size.height)); } protected void paintBackground(){ paintBackground( (Rectangle) null);} protected void paintBackground(Rectangle clip) { Graphics g = buffer.getBackGraphics(); if (clip!= null) g.setClip(clip); paintBackground(g); buffer.blitBack(); g.dispose(); } protected void paintBackground( Graphics g ) { if (background != null) g.drawImage (background, 0,0, this); for (int w=0; w