AccountSetPanelpublic class AccountSetPanel extends imaginary.gui.PersistentSetPanel implements ActionListener, RemotePanelA Java panel with a CardLayout that allows the user
to flip through accounts. |
Fields Summary |
---|
private int | current_account | private Button | next_button | private AccountPanel[] | panels | private Button | previous_button |
Constructors Summary |
---|
public AccountSetPanel(Button[] buttons, imaginary.persist.RemoteLockHolder h)Creates a new AccountSetPanel. The buttons array are the next
and previous buttons placed on the customer panel. Visually,
they fit better on the customer panel. Process-wise, however,
this panel is interested in their events.
super(h);
next_button = buttons[0];
previous_button = buttons[1];
createComponents();
| public AccountSetPanel(Button[] buttons, imaginary.persist.RemoteLockHolder h, imaginary.persist.RemotePersistentSet set)Constructs an AccountSetPanel observing the specified set.
super(h, set);
next_button = buttons[0];
previous_button = buttons[1];
createComponents();
|
Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent event)This method is new to JDK 1.1. It handles action events for
components this class has expressed interest in. In the case
of the account set panel, we want to know when one of the buttons
are clicked.
Button b = (Button)event.getSource();
// the user clicked next
if( b == next_button ) {
// flip to the next account in the card layout
((CardLayout)getLayout()).next(this);
// up the marker
current_account++;
// if this is the last account, disable the next button
if( current_account == panels.length ) {
next_button.enable(false);
}
// if this is not the first account, enable the previous button
if( current_account > 1 ) {
previous_button.enable(true);
}
}
else {
// flip to the previous account in the card layout
((CardLayout)getLayout()).previous(this);
// decrement the marker
current_account--;
// if this is the first account, disable the previous button
if( current_account < 2 ) {
previous_button.enable(false);
}
// if this is not the last account, enable the next button
if( current_account < panels.length ) {
next_button.enable(true);
}
}
| protected void | cleanUp()When the window gets destroyed or this panel is removed,
cleanUp() gets called to allow the panel to remove itself
from the observer list of its set.
RemoteObservable o = getObserved();
if( o != null ) {
try {
o.deleteObserver(this);
}
catch( RemoteException e ) {
}
}
if( panels != null ) {
for(int i=0; i<panels.length; i++) {
panels[i].cleanUp();
}
}
| protected void | createComponents()Places the individual widgets on the panel.
RemoteAccountSet set = (RemoteAccountSet)getObserved();
RemotePersistent[] accounts;
// CardLayout allows us to view one account panel at a time
setLayout(new CardLayout(0,0));
// Don't draw anything if no set is being observed
if( set == null ) {
return;
}
accounts = set.getPersistents();
current_account = 1;
panels = new AccountPanel[accounts.length];
// For each observed account, add an account panel
for(int i=0; i<accounts.length; i++) {
panels[i] = new AccountPanel(getLockHolder(),
(RemoteAccount)accounts[i]);
panels[i].reshape(insets().left + 24,insets().top + 132,384,120);
add("" + i, panels[i]);
}
previous_button.addActionListener(this);
previous_button.enable(false);
next_button.addActionListener(this);
if( panels.length < 2 ) {
next_button.enable(false);
}
| public bank.server.RemoteAccount | getSelectedAccount()
AccountPanel acct_panel = panels[current_account-1];
return (RemoteAccount)acct_panel.getObserved();
| public void | observeChange()Implementation of the ChangeObserver method for handling changes
in observed objects.
// Since this application does not support the addition
// or deletion of accounts, it will not actually
// observe any changes. If it did, however, you would use
// this method to add new panels or remove deleted ones
|
|