How to get the timer to return time java

后端 未结 1 844
独厮守ぢ
独厮守ぢ 2021-01-27 22:49

Once I start running the timer, how do I get it to return how long has passed? Can this timer be set visible?

相关标签:
1条回答
  • 2021-01-27 23:24

    The object that you pass as second argument to the Timer constructor implements ActionListener. Through that interface it receives a call to its actionPerformed method upon each alarm from the timer. The actionPerformed method has an ActionEvent parameter whose method getWhen gives the timestamp. You will need to store the original timestamp somewhere accessible if you want the ActionListener to compute the elapsed time.

    A Swing Timer is a mechanism with no graphical representation of its own. If you like, your ActionListener can implement a graphical representation of the timer. It can be a graphic component such as a JPanel and its actionPerformed method can cause it to respond visibly, perhaps by drawing something, each time that the timer goes off.

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