![]() |
![]() |
![]() |
![]() |
Adding code
The layout for the Transaction Dialog is finished. Now we want to add some code to this Dialog.
The Dialog needs a variable to hold the amount that the user enters.
- Choose 'Goto declaration code' from the Code menu in the Composer.
- Press the Code Sourcerer button.
- Choose 'Declare a new variable' and press Next.
- Choose 'float' from the 'primitive' choice box.
- Enter 'amount' into the 'Choose its name' field.
- Choose 'private' in the accessibility group.
- Press Next.
- Leave the initial value at 0.0 and press Done.
The Dialog needs methods to access the 'amount'.
- Choose 'Goto method code' from the Code menu in the Composer.
- Type in the following lines. (Much of this can be generated using the Code Sourcerer, but we'll type it to save time).
In order for declaration and method code to be integrated into the Working Model, the program needs to be initialized.
- Choose 'Initialize Class' from the Program menu. (This executes any variable and method declarations, resets all components, and executes any constructor code as well.)
Now we'll add some code to the 'Command' button and test the Dialog.
- Press the Command button in the Working Model. Its properties appear in the Composer.
- Choose the 'Listeners' tab and check 'Listen for action events'.
- Choose the newly added 'Action' tab.
- Press the Code Sourcerer button and choose 'Ask a part about one of its properties...'. Press Next.
- Choose 'amountField'. Press Next.
- Choose 'get value as a float'. Press Done.
- Replace the suggested new variable 'float value' with 'amount'. Press Ok.
- Press the Code Sourcerer button again and choose 'Change a property of an existing part...'. Press Next.
- Choose 'TransactionDialog' from the list. Press Next.
- Choose 'Dispose of this Dialog'. Press Done.
Data Representations, Inc. http://www.datarepresentations.com support@datarepresentations.com sales@datarepresentations.com |
![]() |
![]() |
![]() |
![]() |