创建一个线程的时候用,比如:
class Example implements Runnable{
public void run(){
//....
}
public static void main(String[] args){
Thread t = new Thread(this);
t.start();
}
}
class Example implements Runnable{
public void run(){
//....
}
public static void main(String[] args){
Thread t = new Thread(this);
t.start();
}
}
但由于JAVA是单继承的语言,不能继承多个类,所以如果你这个程序需要继承其它的类,而又要实现多线程的功能,就只好使用Runnable这个接口了。
方法 public void run
难道定义 我的类 extends JPanel implements Runnable
我需要一个线程管理一个界面,该怎么办?
Thread(Runnable runImpl)
一个类实现了 Runnable 接口后,即意味着可以根据该类构造一个线程!线程管理一个界面??
定义类(假设该类的一个实例是 aaaa) 实现 Runnable 接口,在其 run 方法中实现管理方法啊!
然后,
在 main 函数中(或者你的其他地方代码) new Thread(aaaa).start()啊!