Version 8 (modified by gb, 13 years ago) (diff)


Easy GUI Currency Converter

Easy GUI is a high-level interface for creating windows, dialogs, menus, and simple graphics. This example implements the end-user functionality of Apple's Currency Converter example, but it uses Easy GUI rather than Cocoa. It does not duplicate the Model-View-Controller implementation used by the Cocoa example.

(in-package :easygui-user)

(defclass converter-window (window)
   (:default-initargs :size (point 383 175)
     :position (point 125 513)
     :title "Currency Converter"
     :resizable-p t #+not-yet nil
     :minimizable-p t))

(defmethod initialize-view :after ((cw converter-window))
  (let ((currency-form (make-instance 'form-view
                          :autosize-cells-p t
                          :interline-spacing 9.0
                          :position (point 15 70)                          
                          :size (point 353 90)))
        (convert-button (make-instance 'push-button-view
                           :default-button-p t
                           :text "Convert"
                           :position (point 247 15)))
        (line (make-instance 'box-view
                 :position (point 15 59)
                 :size (point 353 2))))
    (setf (action convert-button)
          #'(lambda ()
              (setf (entry-text currency-form 2)
                     (* (read-from-string (entry-text currency-form 1))
                        (read-from-string (entry-text currency-form 0)))))))
    (add-entries currency-form
                 "Exchange Rate per $1:" "Dollars to Convert:"
                 "Amount in other Currency:")
    (add-subviews cw currency-form line convert-button)
    (window-show cw)))

;(make-instance 'converter-window)