我尝试从一个类中创建两个移动对象。我想控制它们,但 JApplet 没有用线程打开。
我的代码:
import java.awt.Graphics;
import javax.swing.JApplet;
class RunnableThread extends JApplet implements Runnable{
Thread runner;
String name;
public RunnableThread(String namex){
name=namex;
}
public void init(){
setSize(200,300);
}
public void paint(Graphics g){
g.drawLine(20, 20, 50, 50);
}
public void run(){
System.out.println("test"+name);
}
}
import java.util.logging.Level;
import java.util.logging.Logger;
public class RunnableTest{
public static void main(String args[]){
RunnableThread bt1=new RunnableThread("test 1");
RunnableThread bt2=new RunnableThread("test 2");
Thread btt1=new Thread(bt1);
Thread btt2=new Thread(bt2);
btt2.start();
btt1.start();
}
}