This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ///paint/// Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "///paint///" Watch "///paint///" New topic
Author

///paint///

chao-long liao
Ranch Hand

Joined: Jul 29, 2001
Posts: 78
JohnJuntMockExam..
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 answer is B,I don't know the difference between a,b and c,can any one help me to figure out the concept.thanks.
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
Hi, Chao-long
RHE book fully describes repaint(), update(),paint() methods. A small quote from this book:

.....
The code above shows the preferred approach to handling events that cause the screen to be changed: event handlers store information in instance variables and then call repaint(), and paint() draws the screen according to the information in the instance variables. The two benefits of this approach are
� The screen is correctly repaired when the environment spontaneously calls paint().
� The Virtual Machine never gets overwhelmed by events.
If you want to accumulate dots, rather than have each dot cleared away when a new one is to be drawn, you can always override update() so that it does not clear. All update() needs to do in this case is call paint(), as shown below:
1. public void update(Graphics g) {
2. paint(g);
3. }

repaint() calls update() and update() calls paint().
Jamal Hasanov
www.j-think.com
chao-long liao
Ranch Hand

Joined: Jul 29, 2001
Posts: 78
Thanks,you are so kind.
Actually I have read the page you mentioned in RHE book,but I still confuesd.
Let me simplify my question.Why the answer of following question is "b" ??how about "a"?
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.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
there is no method called paint().
there is paint(Graphics g ).
since you cant (or wouldnt advise) create a graphics pbject then you should use the repaint() method who does the job for you.
Alan Chong
Ranch Hand

Joined: Jun 05, 2002
Posts: 106
Instead of calling paint() method, calling repaint() method make sure that the screen is
not updated more than ten times per second.
Too many updates will degrade performance.
Paul Villangca
Ranch Hand

Joined: Jun 04, 2002
Posts: 133
- Calling paint(Graphics g) will work, because the method will draw the screen again (assuming you have created a Graphics object using the getGraphics() method of the Component class).
- Calling update() will also work, because it calls the paint() method.
However, the question asks for the most appropriate answer (which is the call to repaint() ), because in addition to calling update() (which in turn call paint() ), it also schedules the calls to these methods for optimum CPU usage, as well as other benefits.
There are cases when repaint() isn't the best choice to use (i.e. in animation), but in most cases, repaint() will do the job fine.
 
wood burning stoves
 
subject: ///paint///
 
Similar Threads
From JONH hunts mock exam
paint, repaint
One Mock question
Calling the paint() method of superclass()
Answers on Fill in the blank question