How to display and compute time in java [closed]

*爱你&永不变心* 提交于 2019-12-13 06:26:34

问题


I am building a java application.I need to monitor how long the user is staying on a particular page.The timer should start on user entering the page.It should pause on user moving away to another page and resumes when user returns to the "page(panel)".It should work like a stopwatch on a particular panel.


回答1:


There are a bunch of Stopwatch implementations floating around. I know the Guava library as one: http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Stopwatch.html. We use one called Java Simon to measure the time it takes to make it through a REST call: https://code.google.com/p/javasimon/

I don't think there is anything for free that will record the timing of page transitions through a JPanel, so you're going to need to figure out the event model yourself. But the stopwatch logic itself is really simple.




回答2:


If you can live without detecting that the user actually sits in front of the screen, you can simply use System.currentTimeMillis intialized when user enters the page.

Another option is to use the JAMon API, it comes with AOP.



来源:https://stackoverflow.com/questions/21694833/how-to-display-and-compute-time-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!