wood burning stoves
The moose likes Applets and the fly likes update() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "update() method" Watch "update() method" New topic

update() method

Gotham Sewani

Joined: Feb 16, 2007
Posts: 15
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

Joined: Mar 22, 2005
Posts: 42965
#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

Joined: Feb 16, 2007
Posts: 15
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>
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

Joined: Feb 16, 2007
Posts: 15
no replies?
I agree. Here's the link: http://aspose.com/file-tools
subject: update() method
It's not a secret anymore!