The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes repaint and update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "repaint and update" Watch "repaint and update" New topic

repaint and update

teja nelluri

Joined: Jun 22, 2000
Posts: 8

hi everybody,

can anybody please exaplain differece between
repaint and update.

Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
I took the following method descriptions from Java API documentation ( which is free and useful ) for the java.awt.Component class -

This method causes a call to this component's update method as soon as possible
Clears this component by filling it with the background color.
Sets the color of the graphics context to be the foreground color of this component.
Calls this component's paint method to completely redraw this component.
Paints this component. This method is called when the contents of the component should be painted in response to the component first being shown or damage needing repair. The clip rectangle in the Graphics parameter will be set to the area which needs to be painted.

Hence the order of invocation is repaint->update->paint. Marcus Green has a neat acronym to help you remember this ( Thanks Marcus! ) - Really-Ugly-Painting.
It is recommended that you call repaint() instead of update(), unless you have a very compelling reason to do so, since the repaint() schedules a paint to occur while update tries do do it immediately and might make your program resource intensive.
Hope this helps.
[This message has been edited by Ajith Kallambella (edited August 01, 2000).]

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
I agree. Here's the link:
subject: repaint and update
It's not a secret anymore!