Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very basic applet question

Status
Not open for further replies.

dbrb2

Instructor
Jul 19, 2004
121
GB
I'm trying to work out what the process is when a simple hello world applet runs.

The init() method is called by default when the class is used, I assume. However, the paint method is the one that actually displays text. When / where is that called from?
It appears to be passsed a parameter of type Graphics, but I can't see where any of this is happening ...

Ben


import java.awt.Graphics;
public class HelloWorld extends java.applet.Applet {
public void init() {
resize(150,25);
}
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
}
}

 
Yes - that confused me in the beginning too.
It's called behind the scenes, when painting is needed.

Perhaps the user opens another programm, hiding yours.
Then he closes the other programm. Now painting is needed and called.

Or you minimized the browser. By making it visible again, the painting is (and needs to be called) called again.

seeking a job as java-programmer in Berlin:
 
paint() is a method of the Container class. In an applet, this is the bit visible to the user.

The following is from:
System-triggered Painting:

In a system-triggered painting operation, the system requests a component to render its contents, usually for one of the following reasons:

(1) The component is first made visible on the screen.

(2) The component is resized.

(3) The component has damaged that needs to be repaired. (For example, something that previously obscured the component has moved, and a previously obscured portion of the component has become exposed).
 
Thanks. Its all a bit confusing .... In C for instance, nothing happens unless I tell it to - no functions are called, or classes instantiated etc.

However, here there seems to be some controlling body that can, for instance, call the neccesary methods to repaint the screen as neccesary. What is this controlling body?

Sorry if I'm talking gibberish ...:p


Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top