【发布时间】:2015-01-28 18:35:03
【问题描述】:
我正在尝试将节拍器添加到程序中,这是它的类
public void playMet() throws IOException
{
int tempo = Integer.parseInt(met_speed.getText());
//tempo = 60/tempo;
double delay = 60/tempo*1000;
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
while(Play.isSelected()){
try {
playSound("Click1.wav");
System.out.println("beep");
Thread.sleep((long) delay);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
t.start();
}
如果我将值设置为 60bpm,或每秒一次,程序运行良好。如果我将其设置为其他任何值,它会忽略睡眠。 “system.out.println..”用于测试,playSound 是一个播放 wav 文件的类。
不确定我是否忽略了一些明显的事情,或者我是否偏离了我应该做的事情
【问题讨论】:
标签: java multithreading sleep