The paint()
method of a JFrame object is used by
the Java system when it wants to paint on the monitor screen.
It is a mistake for you to call it directly.
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:
When the system decides to paint on the monitor screen,
it first does its work, then at the end calls the paint()
method that is part of the MyFrame
object in main memory.
The drawString()
method in paint()
puts some
text on the monitor.