Reputation: 493
import java.applet.Applet;
import java.awt.Graphics;
public class MyApplet extends Applet {
public void paint(Graphics g) {
System.out.println("This the test.");
g.drawString("This the test.", 10, 20);
}
}
Output in the console is:
This the test.
This the test.
Upvotes: 2
Views: 2449
Reputation: 1746
The paint method is called anytime the Applet needs to be drawn again. It is called when the size changes, the gui goes invisible and visible again or you can call it manually using repaint()
. Sometimes it's called hundreds of times if nessecary, so this behavior is absolutely fine.
Upvotes: 0
Reputation: 2618
In GUI programming, the paint()
method will be called as many times as necessary. If you put another window over your GUI then the paint()
method will be called. If you then minimize that window and make your GUI visible again then the paint()
method will be called again. And so on.
So if you have something that is a problem if the paint()
method is called more than once, you have done it wrong. Don't do it that way. The paint()
method should only redraw its target from existing data, it should never have to do calculations to figure out what to paint.
Upvotes: 4