FileDocCategorySizeDatePackage
BankClientFrame.javaAPI DocExample5557Thu Nov 08 00:22:52 GMT 2001com.ora.rmibook.chapter15.bank.applications

BankClientFrame

public class BankClientFrame extends ExitingFrame

Fields Summary
private JTextField
_accountNameField
private JTextField
_balanceTextField
private JTextField
_withdrawalTextField
private JTextField
_depositTextField
private JTextField
_contextTextField
private Account
_account
String
idNumber
Constructors Summary
Methods Summary
protected voidbuildGUI()


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

        contentPane.add(buildMainPanel(), BorderLayout.CENTER);
        setContentPane(contentPane);
        setSize(250, 300);
    
private javax.swing.JPanelbuildMainPanel()

        JPanel actionPanel = new JPanel(new GridLayout(7, 2));

        actionPanel.add(new JLabel("Account Name:"));
        _accountNameField = new JTextField();
        actionPanel.add(_accountNameField);

        actionPanel.add(new JLabel("Context Name:"));
        _contextTextField = new JTextField();
        actionPanel.add(_contextTextField);

        actionPanel.add(new JLabel("Withdraw:"));
        _withdrawalTextField = new JTextField();
        actionPanel.add(_withdrawalTextField);

        actionPanel.add(new JLabel("Deposit:"));
        _depositTextField = new JTextField();
        actionPanel.add(_depositTextField);

        actionPanel.add(new JLabel("Balance:"));
        _balanceTextField = new JTextField();
        _balanceTextField.setEnabled(false);
        actionPanel.add(_balanceTextField);

        JButton getBalanceButton = new JButton("Get Balance");

        getBalanceButton.addActionListener(new GetBalanceAction());
        actionPanel.add(getBalanceButton);

        JButton withdrawalButton = new JButton("Make WithDrawal");

        withdrawalButton.addActionListener(new WithdrawAction());
        actionPanel.add(withdrawalButton);

        JButton depositButton = new JButton("Make Deposit");

        depositButton.addActionListener(new DepositAction());
        actionPanel.add(depositButton);

        return actionPanel;
    
private voidgetAccount()

        try {
            Context baseContext = BaseContextImpl.getStubFromServer("127.0.0.1");
            Path path = Path.buildPath(new String[] {_contextTextField.getText()}
                );

            _account = (Account) baseContext.lookup(path, _accountNameField.getText(), null);
        } 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(idNumber);

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