import java.applet.Applet;
import java.awt.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** A demonstration of the fact that the system
 *  calls <CODE>paint</CODE> with a clipping region
 *  set if a window is partially obscured and
 *  reexposed. Try covering up just part of the applet.
 *  When it is uncovered, only the previously
 *  covered part will change color. So in the unusual
 *  case that the result of paint is different every
 *  time (but repaint isn't being called), this will
 *  fail unless you change the clipping region.
 */

public class Clip extends Applet {
  private int paintCount = 0;
  private Color[] colors =
    { Color.lightGray, Color.gray, Color.darkGray };

  public void paint(Graphics g) {
    g.setColor(colors[paintCount]);
    g.fillRect(0, 0, size().width, size().height);
    paintCount = (paintCount + 1)%3;
  }
}

