很高兴没人回答你的问题,这样你必须采纳我的意见了,
你在停止按钮按下时,在线程中的循环就退出了,线程就结束了,你再将running设置为ture 也没有线程接受。
最简单的解决方法:
private class MyLabel extends JLabel {
public MyLabel() {
new Thread(new Runnable() {
public void run() {
while(true)
{
while (running) {
int num = (int) (Math.random() * 10);
MyLabel.this.setText(String.valueOf(num));
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
}
}
}).start();
}
}
这个里面加上while(true)
已经加进去了,我试过可以了,
还有,你的注释写的太少了。