TOC PREV NEXT INDEX



Deposits and Withdrawals


We need to add some code to keep track of and let the user know the current account balance.

  1. Choose 'Goto declaration code' from the Code menu.
  2. Press the Code Sourcerer button and choose 'Declare a new variable...'. Press Next.
  3. Choose 'float' from the 'primitive' choice box.
  4. Enter 'balance' into the 'Choose its name' field.
  5. Choose 'private' in the accessibility group. Press Next.
  6. Leave the initial value at 0.0 and press Done.
  7. Choose 'Goto method code' from the Code menu.
  8. Type the following method
public void setBalance(float f) {
balance = f;
output.setText("Your balance is $"+balance);
}
  1. Choose 'Goto constructor code' from the Code menu.
  2. Type the following
setBalance(0);

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".

  1. Press the 'Make a deposit' button to view its properties.
  2. Enable the Action event for this button and goto its Action page.
  3. Press the Code Sourcerer button.
  4. Choose 'Window operations...'. Press Next.
  5. Choose 'Open a new Frame/Window/Dialog...'. Press Next.
  6. Choose 'TransactionDialog' or 'FinishedTransactionDialog' if you are using the Simplicity for Java Demo.
  7. Enter 'dialog' where the Code Sourcerer asks for a name for this window.
  8. Press Done. Two lines of code are produced. The first creates the Dialog. The second shows the dialog on the screen.
  9. Insert a second line and add a fourth line so that the code reads
TransactionDialog dialog = new
TransactionDialog(_getFrame(this));
dialog.setCommand("Deposit");
dialog.show();
setBalance(balance += dialog.getAmount());
  1. 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.
  2. Select 'Copy' from the pop-up menu.
  3. Press the 'Make a withdrawal' button to view its properties.
  4. Enable the Action event for this button and goto its Action page.
  5. Select 'Paste' from the pop-up menu.
  6. Change the "Deposit" command to "Withdrawal".
  7. 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
TOC PREV NEXT INDEX