Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

repaint and update

 
teja nelluri
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi everybody,

can anybody please exaplain differece between
repaint and update.

thanks
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
teja,
I took the following method descriptions from Java API documentation ( which is free and useful ) for the java.awt.Component class -


repaint
This method causes a call to this component's update method as soon as possible
update
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.
paint
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.
Ajith
[This message has been edited by Ajith Kallambella (edited August 01, 2000).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic