User's Guide


Adding functions

The last several lines of the addButtonsTo: method specifies that when a button is pressed, the method pressed:clientData:callData: will be called. The name of the button is passed as the argument clientData. Now add this instance method to the class STCalculator:

pressed: aWidget clientData: clientData callData: callData
    "Private - A button has been pressed. The button name is clientData,
    so we can figure out whether to display a character or perform an
    operation."
    ( #('.' '0' '1' '2' '3' '4' '5' '6' '7' '8' '9')
        includes: clientData)
            ifTrue: [ self insert: clientData ]
            ifFalse: [ self doFunction: clientData ].
    textWidget isDestroyed
        ifFalse: [ textWidget setInputFocus ].

This method checks to see whether the button is a number or a period. If it is, the method calls another method to display it. If it is not, the method calls a different method to handle the calculator function. The last statement keeps the text widget from losing focus after a button is pressed.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]