Answer:

The paint() method of a JFrame object is called by the Java system when it wants to paint on the monitor screen. It is a mistake for you to call it directly.

Picture of MyFrame

The picture for this program is similar to that for the previous program. The class TestFrame2 holds a static main() method which is where the program starts running. Then an object is constructed using the class definition for MyFrame. The variable frame refers to this object. Here is a picture of what is going on:

diagram of myframe

When the system decides to paint on the monitor screen, it first does the routine work of drawing the frame. Then, when that is done, it calls the paint() method of the MyFrame object in main memory to finish the drawing. The drawString() method in our paint() puts some text on the monitor. Typical paint() methods do much more.

QUESTION 9:

Why not use System.out.println("Some Message")
to put some text on the monitor?