FileDocCategorySizeDatePackage
AccountPanel.javaAPI DocExample5009Fri Jun 27 17:33:12 BST 1997bank.client

AccountPanel

public class AccountPanel extends imaginary.gui.PersistentPanel implements RemotePanel
An AccountPanel displays information for a single bank account.

Fields Summary
private TextField
balance_field
private Label
balance_label
private CheckboxGroup
cb_group
private boolean
changed
private Checkbox
checking_cb
private TextField
id_field
private Label
id_label
private Checkbox
savings_cb
Constructors Summary
public AccountPanel(imaginary.persist.RemoteLockHolder h)
Constructs a new AccountPanel associated with a specific RemoteLockHolder.

param
h the RemoteLockHolder associated with this panel's edits


      
                           
         
        super(h);
        createComponents();
    
public AccountPanel(imaginary.persist.RemoteLockHolder h, bank.server.RemoteAccount a)
Constructs a new AccountPanel for the specified account.

param
h the RemoteLockHolder associated with this panel's edits
param
a the bank account to display

        super(h, a);
        createComponents();
    
Methods Summary
protected voidcleanUp()
When the window containing this is closed or the panel is removed, it should call cleanUp() to clean up any observer relationships.

        RemoteObservable o = getObserved();

        if( o != null ) {
            try {
                o.deleteObserver(this);
            }
            catch( RemoteException e ) {
            }
        }
    
public voidcreateComponents()
Puts the panel's widgets on the panel

        setLayout(null);
        { // check boxes
            cb_group = new CheckboxGroup();
            checking_cb = new Checkbox("Checking", cb_group, false);
            checking_cb.enable(false);
            checking_cb.reshape(12,12,84,24);
            add(checking_cb);
            savings_cb = new Checkbox("Savings", cb_group, false);
            savings_cb.enable(false);
            savings_cb.reshape(12,48,84,24);
            add(savings_cb);
        }
        { // ID
            id_label = new Label("Account ID:",Label.RIGHT);
            id_label.reshape(96,12,88,24);
            add(id_label);
            id_field = new TextField();
            id_field.setEditable(false);
            id_field.reshape(192,12,124,28);
            add(id_field);
        }
        { // balance
            balance_label = new Label("Balance:",Label.RIGHT);
            balance_label.reshape(108,48,76,24);
            add(balance_label);
            balance_field = new TextField();
            balance_field.setEditable(false);
            balance_field.reshape(192,48,124,24);
            add(balance_field);
        }
        refresh();
    
public voidobserveChange()
This implements the ChangeObserver method inherited from PersistentPanel that handles responding to changes in the observed account.

        refresh();
    
public voidrefresh()
Displays current account data on the screen.

        RemoteObservable o = getObserved();

        if( o == null ) {
            id_field.setText("");
            balance_field.setText("");
            checking_cb.setState(true);
            savings_cb.setState(false);
        }
        else {
            RemoteAccount a = (RemoteAccount)o;

            try {
                NumberFormat f = NumberFormat.getCurrencyInstance();
                
                id_field.setText("" + a.getId());
                balance_field.setText(f.format(a.getBalance()));
                if( a.getAccountType().equals("C") ) {
                    checking_cb.setState(true);
                    savings_cb.setState(false);
                }
                else {
                    checking_cb.setState(false);
                    savings_cb.setState(true);
                }
            }
            catch( RemoteException e ) {
                e.printStackTrace();
                id_field.setText("");
                balance_field.setText("");
                checking_cb.setState(true);
                savings_cb.setState(false);
            }
        }