FileDocCategorySizeDatePackage
TransferDialog.javaAPI DocExample5287Sun Mar 02 22:31:32 GMT 1997bank.client

TransferDialog

public class TransferDialog extends Dialog implements ActionListener, TextListener

Fields Summary
private bank.server.RemoteAccount
account
private Choice
account_choice
private Label
account_label
private TextField
amount_field
private Label
amount_label
private bank.server.RemoteCustomer
customer
private Button
ok_button
private Button
cancel_button
Constructors Summary
public TransferDialog(Frame parent, boolean modal, bank.server.RemoteAccount acct)


           
        super(parent, modal);
        setTitle("Transfer Funds");
        setLayout(null);
        addNotify();
        resize(insets().left + insets().right + 284,insets().top +
               insets().bottom + 149);
        setBackground(new Color(12632256));
        try {
            account = acct;
            customer = account.getCustomer();
            { // amount
                amount_label = new Label("Amount:",Label.RIGHT);
                amount_label.reshape(insets().left + 48,insets().top + 12,
                                     60, 24);
                add(amount_label);
                amount_field = new TextField();
                amount_field.addTextListener(this);
                amount_field.reshape(insets().left + 120,insets().top + 12,
                                     120, 24);
                add(amount_field);
            }
            { // account ID
                RemoteAccount[] accts = customer.getAccounts();
                
                account_label = new Label("To account:");
                account_label.reshape(insets().left + 24,insets().top + 48,
                                      84, 24);
                add(account_label);
                account_choice = new Choice();
                for(int i=0; i<accts.length; i++) {
                    if( accts[i].hashCode() == account.hashCode() ) {
                        continue;
                    }
                    account_choice.addItem("" + accts[i].getId());
                }
                if( accts.length < 2 ) {
                    ok_button.enable(false);
                }
                add(account_choice);
                account_choice.reshape(insets().left + 120,insets().top + 48,
                                       120, 21);
            }
            { // buttons
                ok_button = new Button("OK");
                ok_button.addActionListener(this);
                ok_button.reshape(insets().left + 60,insets().top + 108,60,24);
                add(ok_button);
                cancel_button = new Button("Cancel");
                cancel_button.addActionListener(this);
                cancel_button.reshape(insets().left + 168,insets().top + 108,
                                      60, 24);
                add(cancel_button);
            }
        }
        catch( RemoteException e ) {
            e.printStackTrace();
        }
    
Methods Summary
public synchronized voidactionPerformed(java.awt.event.ActionEvent event)

        hide();
        if( event.getSource() == ok_button ) {
            BankClient frame = (BankClient)getParent();
            RemoteAccount[] accts;
            float amount;
            int id;

            try {
                id = Integer.parseInt(account_choice.getSelectedItem());
                amount = (Float.valueOf(amount_field.getText())).floatValue();
            }
            catch( NumberFormatException e ) {
                e.printStackTrace();
                return;
            }
            try {
                accts = customer.getAccounts();
                for(int i=0; i<accts.length; i++) {
                    if( accts[i].getId() == id ) {
                        frame.transfer(amount, account, accts[i]);
                        return;
                    }
                }
            }
            catch( RemoteException e ) {
                e.printStackTrace();
                return;
            }
            
        }
    
public synchronized voidtextValueChanged(java.awt.event.TextEvent event)

        String txt = amount_field.getText();
        float amount;

        if( txt.length() < 1 ) {
            ok_button.enable(false);
            return;
        }
        try {
            String sel = account_choice.getSelectedItem();

            amount = (Float.valueOf(txt)).floatValue();
            if( sel != null && sel.length() > 0 ) {
                ok_button.enable(true);
            }
            else {
                ok_button.enable(false);
            }
        }
        catch( NumberFormatException e ) {
            ok_button.enable(false);
        }