This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update() method

 
Gotham Sewani
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just started with applets,and I was reading bout the init(),start(),paint(),stop(),destroy() and update() methods. I read that whenever a part of the appletwindow has to be redrawn:
1. The update() method is called. (BTW is this correct?)
2. The default implmentation of update method sets the the default background color and calls the paint method. (Is this correct?)

If we take the above two points to be correct,then if I override the update method such that it doesnt call the paint method,then will the paint method never be called. (Except maybe at the startup?).
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#1 - That's correct.

#2 - The default implementation of update calls paint, and the default implementation of paint does nothing - so no setting of the background color.

your last question - that's correct, too.
 
Gotham Sewani
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then why does the following code print "In Paint" to the console whenever I minimize and maximize the window? :
import java.awt.*;
import java.applet.*;
/*
<applet code=PaintTest width=100 height=100>
</applet>
*/
public class PaintTest extends Applet {

public void paint(Graphics g) {
System.out.println("In paint");
}


public void update(Graphics g) {
System.out.println("In update");
}

}
 
Gotham Sewani
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no replies?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic