In what situations a paint() is called , in what situations update() is called and in what situations repaint() is called I know repaint()->update()->paint(); I want to know when is paint() called or when is update() called
paint should never be called directly at any time, not by your applet and it isn't supposed to be called by the JVM integrated with a browser. update is the magic method that will get called without your code directly causing it. Any kind of windowing event that requires applications to repaint themselves will result in update being called with an appropriate clipping region.
All the AWT Components know how to draw themselves except Canvas and Containers. The AWT components that draw themselves do it thanks to the code placed in its paint method. Canvas has no code in paint; the programmer has to provide it. I think Containers pass the call to its paint method through the components they contain. paint is called by a unique thread that is responsible for both painting and event handling. This is so to prevent the drawing of a component from being interrupted by other's, or by an event handling process. These events are "enqued" to the same thread, thus they happens sequentially. paint shouldn't be called directly by a program, but a call to repaint should be used to enque a petition for the painting thread to draw the component (calling its paint method). The petition takes the form of a scheduling of a call to the component's update method in the painting thread.
The update method clears the component's background and it call its paint method. Also: AWT calls automatically paint method when a component is first time shown, or whenever is damaged (clipped) [ May 06, 2002: Message edited by: Jose Botella ]
I would like to put Jose's explanations in this way: Mechanism behind these methods is GUI thread. This Thread can be thought of as a big loop that always run, and call methods based on the value of events that have been set since last time loop was run. When a call to show() method of frame is made a "paint" event for the frame is scheduled. GUI Thread starts running and calls the paint() method. When update() method is called it sets an event for GUI thread to call paint() method the next time through the loop. When GUI thread returns from the paint() method, it runs the loop again, sees that a "paint" event has been set, and calls paint() again. Above was explanation for update->paint. Now for repaint->update, its simply a method call in which repaint method call the repaint method of Peer class [Platform dependent implementation] of GUI objects. regards Kapil Sachdeva
Joined: Apr 25, 2002
Thanks for the long reply,but many things bounced my head. can soem one explain in a simple way. what i want most is when a componet resizezs or shadowed by other components which method is called . and also if a componet or container is resized and we want to retain the previous drawn thigs which method to call.. and some basic stuff like that.. thanks for the help