> One thing in particular that bugs me is that I can't figure out when I'm
> supposed to use paint() and when to use repaint() to draw my content.
bacically
paint() is what/where
repaint() is when
consider a simple animation of a ball bouncing around the screen
in paintComponent() (see explanation from EFH) you would have something like this
where
super.paintComponent(g) clears the screen
g.setColor(Color.BLUE) self-explanatory
g.fillOval(x,y,50,50) is what is painted.
i.e. at point x,y size 50,50 a filled oval (circle) will be drawn
now, in a separate
thread, and possibly triggered on program start, or a button click:
in a while() loop (often while(true))
the values of x, and of y, are changed
a call to repaint() - paintComponent will now draw at the new x,y //this is the 'when'
Thread.sleep(whatever milliseconds you want)
the separate thread is required, otherwise the while loop will block the painting
do this and the 'ball' will seem to bounce around the screen
[ July 27, 2006: Message edited by: Michael Dunn ]