joa*_*isk 0 java multithreading while-loop
嗨,我正在做一个相当简单的"卡拉OK"程序...我正在尝试用java鼠标点击开始的线程更改显示的文本.当没有循环并且我重复点击鼠标它可以工作但是当我将无限的while循环添加到thread.run()时它变得卡住......它什么也没做......我做错了什么?这是我的代码:
public class Timer extends Thread {
MainWindow window;
public int timeSec;
ArrayList<Integer> times;
public Song song;
public Timer(MainWindow window){
times = new ArrayList<Integer>();
times.add(10); // de alto
times.add(50); // el carino
times.add(70); // cuando juanita
times.add(92); // Limpia el
times.add(113); // de alto
times.add(160); // sabes
times.add(215); // la cosa esta + o.J
times.add(226); // mira
times.add(244); // ref
times.add(266); // matus
times.add(272); // Janka + krik
times.add(293); // mira
song = new Song();
this.window = window;
timeSec = 0;
//run();
}
public void start(){
run();
}
public void run(){
while (true){
try {
sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
timeSec++;
if (times.contains(timeSec)){
song.next();
}
window.repaint();
}
}
}
Run Code Online (Sandbox Code Playgroud)