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
Thread.sleep(2)不是sleep(2), 还要加上try{}catch块
public void run() { try { while (true) { Thread.sleep(1000); System.out.println("hi"); } } catch (Exception e) { } } 运行西此程序时,每隔1秒钟输出一个hi
{
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
还要加上try{}catch块
try {
while (true) {
Thread.sleep(1000);
System.out.println("hi");
}
} catch (Exception e) {
}
}
运行西此程序时,每隔1秒钟输出一个hi