每当我使用 Thread.sleep(); 在 do while 循环中,提示告诉我,“在循环中调用 Thread.sleep 会导致性能问题。” 我从许多其他网站和书籍中听说过。我可以用什么代替?
这是代码:
import javax.swing.*;
public class Delay {
public static void main(String[] args) throws Exception {
int difficulty;
difficulty = Integer.parseInt(JOptionPane
.showInputDialog("How good are you?\n" + "1 = evil genius...\n"
+ "10 = evil, but not a genius"));
boolean cont;
do {
cont = false;
System.out.println("12");
Thread.sleep(500);
String again = JOptionPane.showInputDialog("Play Again?");
if (again.equals("yes"))
cont = true;
} while (cont);
}
}