java - while 循环内的计时器

标签 java swing loops timer

我如何像 Java 中那样在 while 循环内实现计时器?

while (game not ended) {
//do something
(wait 5 seconds)
}

会是这样吗?:(java.util.Timer)

int delay = 1000; //milliseconds

    while (game not ended) {
        //do something
        new Timer(delay, taskPerformer).start();
    }

最佳答案

您可以使用Threadstaticsleep()方法。

while (game not ended) {
   //do something
  Thread.sleep(5000);
}

关于java - while 循环内的计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16620254/

相关文章:

java - 在java应用程序中使用谷歌地图

java - 在java程序中通过批处理文件设置\获取环境变量

java - 在 Java Swing 中使用表模型显示表标题

c++ - 在二维数组中查找最大的 2x2 平均值

c++ - 以特定方式在 C++ 中打印数字三角形?

c++ - 如何在循环外设置初始值? C++

java - IllegalArgumentException 在 Java 中无法正常运行

java - 如何从 java 程序运行无限循环 shell 脚本

java - 使用 PaintComponent 计算两个矩形的交集

Java Paint 组件刷新率?