Starting the Thread

In this applet, the runner thread starts when the applet’s start() method is called and stop when its stop() method is called.

The start() method is called right after the init() method and every time the program is restarted. Here’s the method:

public void start() {    if (runner == null) {        runner = new Thread(this);        runner.start();    }}

This method starts the runner thread if it is not already started.

The statement runner = new Thread(this) creates a new Thread object with one argument—the this keyword. The this keyword refers to the applet itself, designating it as the class that runs within the thread.

The call to runner.start() causes the thread to begin running. When a thread begins, the run() method ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.