[previous] [up] [next]     [contents] [index]
Next: Using Threads Up: MrEd Applications: An Example Previous: Creating Graphical Elements

Handling Events

We have implemented the graphical aspects of the interface completely, but the only functional aspect of our interface that has been implemented is the ``Quit'' button. To make our interface fully functional, refresh-number-info must be implemented, using the current ``Name'' field and toggle selector values to find a phone number:

  (define refresh-number-info 
    (lambda () 
      (let* ([name (send name-text get-value)] 
             [home? (zero? (send number-selector get-selection))] 
             [number (lookup-number name home?)] 
             [number-string (if number 
                                number 
                                "(Unknown)")]) 
        (send number-text set-value number-string))))
The method get-value extracts the string value of the ``Name'' text field name-text. Similarly, get-selection extracts the index of the selected switch in the ``home''-``office'' toggle selector number-selector. The pre-supplied Scheme procedure lookup-number performs the phone book search, returning either a phone number string or #f. If no number is found in the phone book, the displayed result is ``(Unknown)''. Finally, the set-value method of number-text is invoked to update the ``Number'' display text field.



PLT