繁体   English   中英

Netbeans Swing GUI中的计时器?

[英]Timer in Netbeans Swing GUI?

我正在创建一个connect-4游戏,我想计时完成游戏所需的时间(从玩家单击按钮开始游戏到显示祝贺消息时)。 如果有帮助或有所作为,则我们的程序中包含多个面板。

谢谢

有许多类似的问题会给您一个很好的答案,您是否尝试过使用略有不同的措词来搜索堆栈溢出? 例如,您可以查找“ java时间占用”。


这是获取总时间的一种方法:

//Grab the time when you start
long startTime = System.currentTimeMillis();

//Play game

//When you finish grab the current time and work out the time taken
long totalTime = System.currentTimeMillis() - startTime;    
//Convert into minutes and seconds
int seconds = (int) ((totalTime / 1000) % 60);
int minutes = (int) ((totalTime / 1000) / 60);
//Show time
System.out.println("Time taken: "+minutes+"m, "+seconds+"s");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM