FileDocCategorySizeDatePackage
BankClientFrame.javaAPI DocExample5196Thu Nov 08 00:23:52 GMT 2001com.ora.rmibook.chapter9.applications

BankClientFrame

public class BankClientFrame extends ExitingFrame

Fields Summary
private JTextField
_accountNameField
private JTextField
_balanceTextField
private JTextField
_withdrawalTextField
private JTextField
_depositTextField
private Account
_account
Constructors Summary
Methods Summary
private javax.swing.JPanelbuildActionPanel()

        JPanel actionPanel = new JPanel(new GridLayout(3, 3));

        actionPanel.add(new JLabel("Account Name:"));
        _accountNameField = new JTextField();
        actionPanel.add(_accountNameField);
        JButton getBalanceButton = new JButton("Get Balance");

        getBalanceButton.addActionListener(new GetBalanceAction());
        actionPanel.add(getBalanceButton);
        actionPanel.add(new JLabel("Withdraw"));
        _withdrawalTextField = new JTextField();
        actionPanel.add(_withdrawalTextField);
        JButton withdrawalButton = new JButton("Do it");

        withdrawalButton.addActionListener(new WithdrawAction());
        actionPanel.add(withdrawalButton);
        actionPanel.add(new JLabel("Deposit"));
        _depositTextField = new JTextField();
        actionPanel.add(_depositTextField);
        JButton depositButton = new JButton("Do it");

        depositButton.addActionListener(new DepositAction());
        actionPanel.add(depositButton);
        return actionPanel;
    
private javax.swing.JPanelbuildBalancePanel()

        JPanel balancePanel = new JPanel(new GridLayout(1, 2));

        balancePanel.add(new JLabel("Current Balance:"));
        _balanceTextField = new JTextField();
        _balanceTextField.setEnabled(false);
        balancePanel.add(_balanceTextField);
        return balancePanel;
    
protected voidbuildGUI()

        JPanel contentPane = new JPanel(new BorderLayout());

        contentPane.add(buildActionPanel(), BorderLayout.CENTER);
        contentPane.add(buildBalancePanel(), BorderLayout.SOUTH);
        setContentPane(contentPane);
        setSize(250, 100);
    
private voidgetAccount()

        try {
            _account = (Account) Naming.lookup(_accountNameField.getText());
        } catch (Exception e) {
            System.out.println("Couldn't find account. Error was \n " + e);
            e.printStackTrace();
        }
        return;
    
private MoneyreadTextField(javax.swing.JTextField moneyField)

        try {
            Float floatValue = new Float(moneyField.getText());
            float actualValue = floatValue.floatValue();
            int cents = (int) (actualValue * 100);

            return new PositiveMoney(cents);
        } catch (Exception e) {
            System.out.println("Field doesn't contain a valid value");
        }
        return null;
    
private voidreleaseAccount()

        _account = null;
    
private voidresetBalanceField()

        try {
            Money balance = _account.getBalance();

            _balanceTextField.setText("Balance: " + balance.toString());
        } catch (Exception e) {
            System.out.println("Error occurred while getting account balance\n" + e);
        }