Created
June 28, 2012 16:00
-
-
Save Haroperi/3012175 to your computer and use it in GitHub Desktop.
timer with racket/gui
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/gui | |
; DrRacket, version 5.2.1 | |
; 情報科学類ソフトウェアサイエンス主専攻実験 | |
; M.NAKAJIMA | |
; 2012/06/29 | |
; Create a window and show message. | |
(define frame (new frame% [label "Timer"])) | |
(define msg (new message% [parent frame] | |
[label "Press Start button to start the timer."])) | |
; begin is the time when "Start" button is pressed (in milliseconds) | |
; diff is (- (current-inexact-milliseconds) begin) | |
(define begin 0.0) | |
(define diff 0.0) | |
; Timer callback | |
(define timer (new timer% | |
[notify-callback (lambda () | |
(set! diff (- (current-inexact-milliseconds) begin)) | |
(send msg set-label (number->string diff)))] | |
[interval #f])) | |
; Start button | |
(new button% [parent frame] [label "Start"] | |
(callback (lambda (button event) | |
(set! begin (- (current-inexact-milliseconds) diff)) | |
(send timer start 10)))) | |
; Stop button | |
(new button% [parent frame] | |
[label "Stop"] | |
(callback (lambda (button event) | |
(send timer stop)))) | |
; Reset button | |
(new button% [parent frame] | |
[label "Clear"] | |
(callback (lambda (button event) | |
(set! diff 0) | |
(set! begin (current-inexact-milliseconds)) | |
(send msg set-label (number->string diff)) | |
))) | |
; show window | |
(send frame show #t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment