Java Reference
In-Depth Information
The run-time system calls
start( )
to start the applet running. Inside
start( )
, a new
thread of execution is created and assigned to the
Thread
variable
t
. Then,
stopFlag
is set to
false
. Next, the thread is started by a call to
t.start( )
. Remember that
t.start(
)
calls a method defined by
Thread
, which causes
run( )
to begin executing. It does
not cause a call to the version of
start( )
defined by
Applet
. These are two separate
methods.
4.
Add the
run( )
method, as shown here:
In
run( )
, a call to
repaint( )
is made. This eventually causes the
paint( )
method to
be called, and the rotated contents of
msg
are displayed. Between each iteration,
run( )
sleeps for a quarter of a second. The net effect of
run( )
is that the contents of
msg
are scrolled right to left in a constantly moving display. The
stopFlag
variable is
checked on each iteration. When it is
true
, the
run( )
method terminates.
5.
Add the code for
stop( )
and
paint( )
, as shown here: