第一种延迟
try
{
Thread.currentThread().sleep(1000);//毫秒
}
catch(Exception e){
}
第二种延迟
Timer timer=new Timer();//实例化Timer类
timer.schedule(new TimerTask(){
public void run(){
System.out.println(“退出”);
this.cancel();}},500);//五百毫秒
这种延时比sleep精确。上述延时方法只运行一次,如果需要运行多次, 使用timer.schedule(new MyTask(), 1000, 2000); 则每间隔2秒执行MyTask()