• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

paint, repaint

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys. I appreciated the explanation. it's really helpful.
Nito
 
reply
    Bookmark Topic Watch Topic
  • New Topic