wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "update() method" Watch "update() method" New topic
Author

update() method

Gotham Sewani
Greenhorn

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
Marshal

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


Ping & DNS - my free Android networking tools app
Gotham Sewani
Greenhorn

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>
</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

Joined: Feb 16, 2007
Posts: 15
no replies?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: update() method
 
Similar Threads
threads
Flickering in JApplet
Applet wont load...
repaint()
extends Canvas