public class Test implements java.lang.Runnable{
private Thread t ;
public Text(){
t = new Thread(this);
}
}现在我有一个按钮button_start.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
t.start();
}
});第一次按的时候线程可以启动,第二次按的时候出异常了,怎样让他每按一下按钮都能正常启动线程呢
private Thread t ;
public Text(){
t = new Thread(this);
}
}现在我有一个按钮button_start.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
t.start();
}
});第一次按的时候线程可以启动,第二次按的时候出异常了,怎样让他每按一下按钮都能正常启动线程呢
// private Thread t ;
public Text(){
new Thread(this);
}
}
t.start(); //改为 new Text().start();
private static Array<Thread> t ;
private static count=0;
public Text(){
t.add(new Thread(this));
count++;
}
}button_start.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
t.get(count).start();
}
});
Thread t ; // 去掉那个 private
public Text(){
t = new Thread(this);
}
}
button_start.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
new Text().t.start(); // 每次重新生成一个
}
});
用isAilve()方法 要是线程运行中就返回true,新建或死亡就返回false.button_start.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
if(!(t.isAlive());
{ t = new Thread(this);
}
try
{ t.start(); }
cath(Exception e){}
}
});
public void actionPerformed(final ActionEvent e) {
new Text().t.start(); // 每次重新生成一个
}
});
t = new Thread(this); 他说 this 参数有问题