try {
  Thread.currentThread().sleep(5 * 1000);

catch(InterruptedException e) {}
}
将以上代码加入希望延时的地方sleep()的参数是毫秒值
上面代码的作用是暂停5秒钟

解决方案 »

  1.   

    大哥
    这是一个意思啊
    5*1000意思是告诉看程序的,这是5秒……
    <@_@>
      

  2.   

    延时有两种,一种事用线程,另一种是用timer
    1)try {
      Thread.currentThread().sleep(5 * 1000);

    catch(InterruptedException e) {}
    }
    将以上代码加入希望延时的地方sleep()的参数是毫秒值
    上面代码的作用是暂停5秒钟(不好意思盗版了,向alphazhao表示道歉)2)Timer time1,time2;
    time1=new Timer(1000,this);
    time2=new Timer(2000,boy);//boy对象作计时器的监视器
     time1.start();time2.start();
      public void actionPerformed(ActionEvent e)
    {text1.append("欢迎光临"+"\n") ;
            }
      }
      class Boy implements ActionListener
        {  public void actionPerformed(ActionEvent e)
    {TimeWin.text2 .append("欢迎光临"+"\n") ;
            }
        }试试看,GOOK LUCK!
      

  3.   

    在线程中使用wait()暂停;然后再用notify()来唤醒它;
    注意wait()/notify()都需要放在synchronized程序体中。
      

  4.   

    try{
    Thread.sleep(1000);
    }catch(InterruptedException e){
    System.out.println(e.toString());
    }
    //*可以使程序等待1秒,直接粘贴到你的程序中即可*/另:
    import java.io.IOException;
    //以下代码写在main函数里
    System.out.println("press enter to exit");
    try {
    System.out.read();//read some input from the keyboaed
    }catch(IOException e){    //catch the input exception
    return;           //and just return
    }//*等待回车键,才退出*/
      

  5.   

    路过的,顺便问一句,我看了电子工业出版社出的java专业编程指南,里面98页说“调用notify()时,java没有指定删除哪一个等待线程,你不可能对此做任何假设,因为它可能随jvm版本不同而不同,......由于无法用notify()恢复特定线程,因此只能在只要唤醒一个等待线程而不管唤醒哪一个等待线程时使用”,究竟这里说的是什么意思,是书写错了吗??
      

  6.   

    这好像不难懂啊,意思就是说不能用notify()唤醒特定的某个睡眠中的线程,也就是说用它唤醒的是所有等待线程中的某一个,但是这个线程是跟谁JVM版本不同而不同的。或者说notify()唤醒的线程是哪个不能有你来决定!!!
      

  7.   

    faint
    一个n小的问题,有必要搞得如此复杂么?