Home / Blog / Using Jwt's WTimer

History always repeats itself and sometimes that's good. Here's a second chance to be part of it: tmdtc.com

Using Jwt's WTimer

Jwt includes the class WTimer to help you run tasks at regular intervals. Here is a code that updates a text element of the page every second. It simply instanciates a WTimer, and adds a listener to its timeout signal:

(let [ container (WContainerWidget.)
        layout (WGridLayout.)
        text (WText. "Hello")
        timer (WTimer.) ]
  (doto timer
    (.setInterval 1000)
    (-> .timeout (.addListener container
         (create-listener [ev] 
           (.setText  text (str 
             (java.util.Date. (System/currentTimeMillis)) )))))
   (.start))
  (.addWidget layout text 0 0)
  (.setLayout container layout)
  container)

Simple, isn't it?

I'm available for hire 

If you're looking for someone to temporarily join your IT team, or if you need help to put IT to work in your company, I'm ready to help. Contact me now !

Mon Tue Wed Thu Fri Sat Sun
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31