paint, repaint, update  methods in AWT

(Confusing)

Normally, the programmer does not paint the screen directly.

One reason is that too many paint calls can get backlogged  if the system cannot keep up.

It is better to request  that a paint be done and have the system do the best it can to keep up (not every "frame" will necessarily be seen).

 

Control flow in AWT:

 

  1. In order to accomodate window redrawing and  calls from repaint, you should define paint  to paint the screen (actually you are "over-riding" paint).
  2. update  by default repaints the window in the background  color, then  calls paint.

To avoid flicker, either:

     a) set the background color  to what you want, rather than the default (gray)

or  b)  redefine update so that it does what you  want.

 

The system default update:

 

public void update(Graphics g)
  {
  g.setColor(getBackground());
  g.fillRect(0,0,width,height);
  g.setColor(getForeground());
  paint(g);
  }

 

To Next Slide To Previous Slide To Contents