;; this program demonstrates the use of the border layout primitives (define w (window 100 100 "border demo")) (setlayout w (borderlayout)) (BLadd w BLNORTH (label "Hello world!")) (BLadd w BLCENTER (pad (button "push me") (lambda (e) (setbackgroundcolor w (color 250 250 200))))) (BLadd w BLEAST (choice "a" "b" "c")) (validate w) (show w)
(define w (window 200 200 "add demo"))
(add w (label "a") (label "b") (choice "c" "d" "e")
(grid 2 2 (button "1") (button "2") (button "3") (button "4")))
(validate w)
(show w)
(addErrorHandler F H)
and it produces a new procedure G. The new procedure calls F on its
list of arguments A, and if
an Exception, E, is thrown (e.g. division by zero) while F is evaluating, then G stops
evaluating F and calls the handler H. It passes three arguments (E F A) to H. This
allows the error handler to report the error to the user and possible call F again on
new arguments.
(define safe-divide
(add-error-handler (lambda (x y) (/ x y)) (lambda (e U A) (display (list "Division error" x y)))))
(define win (window 100 100 "choice demo"))
(define CH (choice "Hello" "Bon Jour" "Gutten Tag" "Konichi-wa" "Hola"))
(define T (textfield "" 20))
(define (CHaction e)
(if (equal? (readString CH) "Hello") (writeExpr T "English"))
(if (equal? (readString CH) "Bon Jour") (writeExpr T "French"))
(if (equal? (readString CH) "Gutten Tag") (writeExpr T "German"))
(if (equal? (readString CH) "Konichi-wa") (writeExpr T "Japanese"))
(if (equal? (readString CH) "Hola") (writeExpr T "Spanish"))
)
(add win
(col
(label "Choice demo")
(pad CH CHaction)
T))
(show win)
The program needs to use readString because (read CH) will try
to read the string as a scheme term. So for Bon Jour, it will just read the Bon, and
for Gutten Tag it will just read the Gutten.