import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import com.ms.com.*; import bank.*;
/**
* This class can take a variable number of
parameters on the command
* line. Program execution begins with the main()
method. The class
* constructor is not invoked unless an object of
type 'CheckingClient'
* created in the main() method.
* @com.register (
clsid=DD5AF92C-FBA4-11D2-97E4-006097A7D34F,
typelib=DD5AF92B-FBA4-11D2-97E4-006097A7D34F )
*/
public class CheckingClient extends Form
{
static final int INITIAL_RECORD =
11;
int accountNo;
String name;
double balance;
int count;
public CheckingClient () {
super();
// Required for Visual J++ Form Designer support
initForm();
fillAccountList ();
}
/**
* CheckingClient overrides dispose so it can clean
up the
* component list.
*/
public void dispose() {
super.dispose();
components.dispose();
}
public
void fillAccountList() {
accountList.removeAll ();
count = 0;
boolean bMoreElements = true;
do {
try {
bank.IChecking server=
(bank.IChecking)new bank.Checking ();
bank.IAccountKey key = (bank.IAccountKey)new
bank.CheckingPK ();
key.setKey (count+INITIAL_RECORD);
name = server.getCustomerName (key);
if(name == null)
break;
accountList.addItem ((new
Integer (count+INITIAL_RECORD)).toString ());
key = null;
server = null;
}
catch (Exception ex) {
ex.printStackTrace ();
bMoreElements = false;
}
++count;
} while (bMoreElements == true);
}
private
void retrieveButton_click(Object source, Event e)
{
if (accountList.getSelectedItem () == null)
return;
String accSel = (accountList.getSelectedItem
()).toString ();
accountNo = (new Integer (accSel)).intValue ();
try {
bank.IChecking server=
(bank.IChecking)new bank.Checking ();
bank.IAccountKey key = (bank.IAccountKey)new
bank.CheckingPK ();
key.setKey (accountNo);
balance = server.getBalance (key);
name = server.getCustomerName (key);
numberEdit.setText ( (new Integer
(accountNo)).toString () );
nameEdit.setText (name);
balanceEdit.setText ( (new Double
(balance)).toString () );
key = null;
server = null;
}
catch (Exception ex) {
ex.printStackTrace ();
}
}
private
void addButton_click(Object source, Event e) {
accountNo = count+INITIAL_RECORD;
name = nameEdit.getText ();
balance = ( new Double (balanceEdit.getText ())
).doubleValue ();
if ((accountNo == 0) || (name == null))
return;
try {
bank.ICheckingHome server=
(bank.ICheckingHome)new bank.Checking ();
bank.IAccountKey key = (bank.IAccountKey)new
bank.CheckingPK ();
key.setKey (accountNo);
server.create (key, name, balance);
}
catch (Exception ex) {
ex.printStackTrace ();
}
fillAccountList ();
}
private
void closeButton_click(Object source, Event e)
{
Application.exit ();
}
private
void creditButton_click(Object source, Event e)
{
if (accountList.getSelectedItem () == null)
return;
String accSel = (accountList.getSelectedItem
()).toString ();
accountNo = (new Integer (accSel)).intValue ();
double amount = ( new Double (creditEdit.getText
()) ).doubleValue ();
try {
bank.IChecking server=
(bank.IChecking)new bank.Checking ();
bank.IAccountKey key = (bank.IAccountKey)new
bank.CheckingPK ();
key.setKey (accountNo);
server.credit (amount, key);
balance = server.getBalance (key);
name = server.getCustomerName (key);
numberEdit.setText ( (new Integer
(accountNo)).toString () );
nameEdit.setText (name);
balanceEdit.setText ( (new Double
(balance)).toString () );
key = null;
server = null;
}
catch (Exception ex) {
ex.printStackTrace ();
}
}
private
void debitButton_click(Object source, Event e)
{
if (accountList.getSelectedItem () == null)
return;
String accSel = (accountList.getSelectedItem
()).toString ();
accountNo = (new Integer (accSel)).intValue ();
double amount = ( new Double (debitEdit.getText
()) ).doubleValue ();
try {
bank.IChecking server=
(bank.IChecking)new bank.Checking ();
bank.IAccountKey key = (bank.IAccountKey)new
bank.CheckingPK ();
key.setKey (accountNo);
server.debit (amount, key);
balance = server.getBalance (key);
name = server.getCustomerName (key);
numberEdit.setText ( (new Integer
(accountNo)).toString () );
nameEdit.setText (name);
balanceEdit.setText ( (new Double
(balance)).toString () );
key = null;
server = null;
}
catch (Exception ex) {
ex.printStackTrace ();
}
}
/**
* NOTE: The following code is required by the
Visual J++ form
* designer. It can be modified using the
form editor. Do not
* modify it using the code editor.
*/
Container components = new Container();
ListBox accountList = new ListBox();
Button retrieveButton = new Button();
Button closeButton = new Button();
Button addButton = new Button();
Edit numberEdit = new Edit();
Edit nameEdit = new Edit();
Edit balanceEdit = new Edit();
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
Edit creditEdit = new Edit();
Edit debitEdit = new Edit();
Button creditButton = new Button();
Button debitButton = new Button();
private
void initForm() {
this.setText("CheckingClient");
this.setAutoScaleBaseSize(new Point(5, 13));
this.setClientSize(new Point(300, 336));
accountList.setAllowDrop(true);
accountList.setLocation(new Point(16, 216));
accountList.setSize(new Point(128, 108));
accountList.setTabIndex(0);
accountList.setText("listBox1");
accountList.setUseTabStops(true);
retrieveButton.setLocation(new Point(184, 240));
retrieveButton.setSize(new Point(96, 24));
retrieveButton.setTabIndex(5);
retrieveButton.setText("Retrieve");
retrieveButton.addOnClick(new
EventHandler(this.retrieveButton_click));
closeButton.setLocation(new Point(184, 280));
closeButton.setSize(new Point(96, 24));
closeButton.setTabIndex(4);
closeButton.setText("Close");
closeButton.addOnClick(new
EventHandler(this.closeButton_click));
addButton.setLocation(new Point(96, 112));
addButton.setSize(new Point(96, 24));
addButton.setTabIndex(3);
addButton.setText("Add Record");
addButton.addOnClick(new
EventHandler(this.addButton_click));
numberEdit.setLocation(new Point(120, 16));
numberEdit.setSize(new Point(160, 20));
numberEdit.setTabIndex(10);
numberEdit.setText("-1");
numberEdit.setReadOnly(true);
nameEdit.setLocation(new Point(120, 48));
nameEdit.setSize(new Point(160, 20));
nameEdit.setTabIndex(9);
nameEdit.setText("Nobody");
balanceEdit.setLocation(new Point(120, 80));
balanceEdit.setSize(new Point(160, 20));
balanceEdit.setTabIndex(7);
balanceEdit.setText("-1.0");
label1.setLocation(new Point(16, 16));
label1.setSize(new Point(88, 16));
label1.setTabIndex(13);
label1.setTabStop(false);
label1.setText("Account Number");
label2.setLocation(new Point(16, 48));
label2.setSize(new Point(88, 16));
label2.setTabIndex(12);
label2.setTabStop(false);
label2.setText("Customer Name");
label3.setLocation(new Point(16, 80));
label3.setSize(new Point(88, 16));
label3.setTabIndex(11);
label3.setTabStop(false);
label3.setText("Balance (in US $)");
creditEdit.setLocation(new Point(16, 152));
creditEdit.setSize(new Point(128, 20));
creditEdit.setTabIndex(8);
creditEdit.setText("0");
debitEdit.setLocation(new Point(16, 184));
debitEdit.setSize(new Point(128, 20));
debitEdit.setTabIndex(6);
debitEdit.setText("0");
creditButton.setLocation(new Point(184, 152));
creditButton.setSize(new Point(96, 24));
creditButton.setTabIndex(2);
creditButton.setText("Credit (in US
$)");
creditButton.addOnClick(new
EventHandler(this.creditButton_click));
debitButton.setLocation(new Point(184, 184));
debitButton.setSize(new Point(96, 24));
debitButton.setTabIndex(1);
debitButton.setText("Debit (in US $)");
debitButton.addOnClick(new
EventHandler(this.debitButton_click));
this.setNewControls(new Control[] {
debitEdit,
debitButton,
creditButton,
creditEdit,
label3,
label2,
label1,
balanceEdit,
nameEdit,
numberEdit,
addButton,
closeButton,
retrieveButton,
accountList});
}
/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the
application
* via the command line.
*/
public static void main (String args[])
{
Application.run (new CheckingClient ());
}
}
|