Creating a Count Up timer to Break in java

后端 未结 1 2044
天命终不由人
天命终不由人 2021-01-06 05:31

I\'m trying to implement a timer based scoring system for a puzzle application i am writing.

Can someone provide me with an example case of creating a JLabel or Pane

相关标签:
1条回答
  • 2021-01-06 05:38

    Thats a bit over-complicated. Instead of using seconds, minutes, hours, you could just use java.util.Date, and java.text.SimpleDateFormat for displaying the time passed.

    start = new Date(); // time right now
    sdf = new SimpleDateFormat("hh:mm:ss");
    

    Then later to show what time has passed:

    Date now = new Date();
    sdf.format(new Date(now.getTime() - start.getTime()); //create a date based on time passed
    

    This will have the same effect and be much clearer and more consise.

    0 讨论(0)
提交回复
热议问题