用线程实现了一个棋盘打谱系统,暂停后无法继续。主要是 wait() 和notifyall() 的使用。
public synchronized void run()//没有达到理想中的效果,即点继续播放后还能继续演示
{
// TODO 自动生成方法存根
for(index=0;index<list.size();index++)
{
num=index;
try
{
Thread.sleep(time);
}
catch(Exception ex)
{
}
while(process.equals("暂停演示"))
{
try
{
wait();
}
catch(Exception ex)
{
}
//if(process.equals("继续演示"))
// notifyAll();
}
demoNext(index);
}
if(index>=list.size())
{
demoEnd("演示结束");
next.setEnabled(true);
replay.setEnabled(true);
}
}
}主要是notify 应该放在什么地方。process 是一个JButton类。
请指教!
public synchronized void run()//没有达到理想中的效果,即点继续播放后还能继续演示
{
// TODO 自动生成方法存根
for(index=0;index<list.size();index++)
{
num=index;
try
{
Thread.sleep(time);
}
catch(Exception ex)
{
}
while(process.equals("暂停演示"))
{
try
{
wait();
}
catch(Exception ex)
{
}
//if(process.equals("继续演示"))
// notifyAll();
}
demoNext(index);
}
if(index>=list.size())
{
demoEnd("演示结束");
next.setEnabled(true);
replay.setEnabled(true);
}
}
}主要是notify 应该放在什么地方。process 是一个JButton类。
请指教!
定时读取输入来判断