sleep方法是一个static方法,可以直接调用的,Thread.sleep(long),当然也可以通过对象(可以是Thread及其子类)调用

解决方案 »

  1.   

    public void run()
      {
        for(int j=0;j<=100;j++)
        {
          sleep(2);
          int i=getValue();
          setValue(i+1);
        }
     }但上面这段代码会报错的
    "Frame1.java": Error #: 300 : method sleep(int) not found in class untitled4.JB at line 89, column 7
      

  2.   

    Thread.sleep(2)不是sleep(2),
    还要加上try{}catch块
      

  3.   

    public void run() {
        try {
            while (true) {
                Thread.sleep(1000);
                System.out.println("hi");
            }
        } catch (Exception e) {
        }
    }
    运行西此程序时,每隔1秒钟输出一个hi