![]() |
![]() |
![]() |
![]() |
Deposits and Withdrawals
We need to add some code to keep track of and let the user know the current account balance.
- Choose 'Goto declaration code' from the Code menu.
- Press the Code Sourcerer button and choose 'Declare a new variable...'. Press Next.
- Choose 'float' from the 'primitive' choice box.
- Enter 'balance' into the 'Choose its name' field.
- Choose 'private' in the accessibility group. Press Next.
- Leave the initial value at 0.0 and press Done.
- Choose 'Goto method code' from the Code menu.
- Type the following method
You can test the code that you've typed so far by choosing 'Initialize Class' from the Program menu. The output label should read "Your balance is $0.0".
- Press the 'Make a deposit' button to view its properties.
- Enable the Action event for this button and goto its Action page.
- Press the Code Sourcerer button.
- Choose 'Window operations...'. Press Next.
- Choose 'Open a new Frame/Window/Dialog...'. Press Next.
- Choose 'TransactionDialog' or 'FinishedTransactionDialog' if you are using the Simplicity for Java Demo.
- Enter 'dialog' where the Code Sourcerer asks for a name for this window.
- Press Done. Two lines of code are produced. The first creates the Dialog. The second shows the dialog on the screen.
- Insert a second line and add a fourth line so that the code reads
- Select all of this text by choosing 'Select All' from the pop-up menu. The pop-up menu will appear when you right-click in the Sourcerer, or when you hold down the control key while you click in the Sourcerer.
- Select 'Copy' from the pop-up menu.
- Press the 'Make a withdrawal' button to view its properties.
- Enable the Action event for this button and goto its Action page.
- Select 'Paste' from the pop-up menu.
- Change the "Deposit" command to "Withdrawal".
- Change the += to -= on the last line.
Try testing the 'Make a deposit' and 'Make a withdrawal' buttons. The transaction dialog should appear, asking for an amount. The button should contain a 'Deposit' or 'Withdrawal' label.
Data Representations, Inc. http://www.datarepresentations.com support@datarepresentations.com sales@datarepresentations.com |
![]() |
![]() |
![]() |
![]() |