Hi, The question comes from John Hunt Mock Exam (#45) In order to cause the paint(Graphics) method to execute, which of the following is the most appropriate method to call: A) paint() B) repaint() C) paint(Graphics) D) update(Graphics) E) None � you should never cause paint(Graphics) to execute Select the most appropriate answer. The given answer is B. but I think the D update() is more appropriate, update calls paint() directly and repaint calls update. Could someone input some thought on this? thanks, Nito
nito: Usually it is the repaint() method that you call from your application. The repaint() method in turn calls update(Graphics g) which in turn calls paint(Graphics g). If you want to call the update(Graphics g) method directly, you will need to first get a reference to the graphics context and pass it as a parameter. On the other hand, when you call the repaint() method, AWT takes care of getting a reference to the appropriate graphics context and passing it along to the update(Grahics g) method. This is one reason to use the repaint() method instead of the update(Graphics g) method.
[This message has been edited by thomas (edited August 19, 2000).]
applets are window based programs. the execution of an applet is started and controlled by the AWT(Abstract Window Toolkit). So the applet performs specific actions as directed by the AWT - and then returns control back to the AWT run time system. Now update() and paint() are methods of the applet itself. when the window needs to be updated it must call these methods. But it cannot keep calling these methods - without violating the constraint imposed on it that it must quickly pass back the control to the AWT runtime system. So the way out is to ideally call repaint(), as repaint() is a method defined by the AWT. It causes the AWT to execute a call to the applet's update() method, which in turn calls paint(). Therefore repaint() is the most appropriate ans.