Java's creators have graciously designed two ways of creating threads: implementing an interface and extending a class. Extending a class is the way Java inherits methods and variables from a parent class. In this case, one can only extend or inherit from a single parent class. This limitation within Java can be overcome by implementing interfaces, which is the most common way to create threads. (Note that the act of inheriting merely allows the class to be run as a thread. It is up to the class to start() execution, etc.)
public class CounterThread2 extends Applet implements Runnable
{
Thread t;
int Count;
boolean suspended;
public boolean mouseDown(Event e,int x, int y)
{
if(suspended)
t.resume();
else
t.suspend();
suspended = !suspended;
return true;
}
...
}
No comments:
Post a Comment