The Marquee applet
-
The Java applet consists instructions which the browser executes (init,
start, run)
-
A Thread is a sequence of actions the browser can execute at the same time
it runs the applet
-
The applet must be defined with the RUNNABLE inteface to enable a thread
-
The Thread class belongs to the java.lang package, which is imported automatically
-
Thread.sleep method creates a time delay
-
The Thread.sleep method can be interrupted. It should be run only in a
try{} catch {} loop which will catch the interrupts during sleep and decide
what to do with them.
-
The start-method creates a Thread for the current object (marquee)
-
my_thread.start() starts the thread (in fact it starts the run function
-
Run calls the repaint method which runs the paint function
-
x is moved 10 pixels left and if it reaches the left side of the screen
x will return to width (of the screen)
-
note that run changes the location where the word should be drawn but paint
does the drawing.