;;;
;;; Clock
;;;
;; This program demonstrates how to use a timer
;; together with a GUI.
(require (lib"date.ss"))
;;; GUI
; The GUI consists of a frame with the title "Clock".
; The contents of the frame is a message, where the
; time is written every second.
(defineframe (make-objectframe%"Clock"))
(definetime-message (make-objectmessage%"The time is written here"frame))
(sendframeshow#t)
;;; DATE AND STRING FUNCTIONS
; pad2 makes sure the string length is 2 by padding with
; an extra 0, if neccessary
(define (pad2s)
(if (< (string-lengths) 2)
(string-append"0"s)
s))
; time->string : -> string
; returns a string with the current time
(define (time->string)
(let* ([date (seconds->date (current-seconds))]
[seconds (number->string (date-seconddate))]
[minutes (number->string (date-minutedate))]
[hours (number->string (date-hourdate))] )
(string-append (pad2hours)
":"
(pad2minutes)
":"
(pad2seconds))))
;;; TIMER
; The timer calls the callback function every
; 1000 milliseconds (that is every second)
(instantiatetimer% ()
(notify-callback (lambda ()
(sendtime-messageset-label (time->string))))
(interval1000)
(just-once?#f) )