94
1 1992-2007 Pearson Education, Inc. All rights rese Case Studies

1992-2007 Pearson Education, Inc. All rights reserved. 1 Case Studies

Embed Size (px)

Citation preview

1

1992-2007 Pearson Education, Inc. All rights reserved.

Case Studies

2

1992-2007 Pearson Education, Inc. All rights reserved.

Cases Covered

Design methodology Simple aritmetic opperations

– boundary-control– Without database connection

Pizza order– boundary – control – entity– Without database connection

Human resource monitoring– boundary – control – entity– With database conection

ATM – boundary – control – entity– With database conection

3

1992-2007 Pearson Education, Inc. All rights reserved.

Design Methodology

Three classes– Bounary – get information from the user and present

information

– Entity – internal representations of entities- Emloyees

- Students

- Accounts…

– Control – execute main opperaiions - All other classes comunicate with control class

- Sent messages get permisions

4

1992-2007 Pearson Education, Inc. All rights reserved.

Relationb etween classes

Boundary

frames

Boundary

database

Entity

contro

Entity

5

1992-2007 Pearson Education, Inc. All rights reserved.

Boundary Classes

Boundary classes get information from the user or external sources such as databeses

Or present information to external sources – Users, databases…

GUIs– Form Frames– Insert components on frames– Register events– When an event occurs – invoke relevant methods of handler objects

such as- actionPerformed, itemStateChanged

– invokes control classes- Sent infromation in components to control class- Let control class get the information from components

6

1992-2007 Pearson Education, Inc. All rights reserved.

Boundary Classes

The control class process the information– Makes some calculations– Communicates with other entity or boundary classes– Register the changes in entities or store in databases– Finally send back information to the GUIs

Examples:– Student registration: when a corse is seleced after the

actionEvent - the list of selected courses are send to the control class - Or the control class is invoked to get the selected courses

from JLists

7

1992-2007 Pearson Education, Inc. All rights reserved.

Boundary Classes

Depositing money– When an amount of meney to be deposited is entered into a

JTextField

– And an deposit button is pressed – generate an actionEvent

– The actionPerformed method of the event handler

– Send the money together with the deposit mesage to the contol

– Or invokes the control class that a deposiing money shold be processed so that the control class get the money depositted from the relevant JTextField

8

1992-2007 Pearson Education, Inc. All rights reserved.

Control Class

Get and send infromation to boundry classes Communicate with entity classes

– Objects or list of objects

internal processing of information Example

– When a request comes about withdrawing money from an account

- Get the infromation – amount of money, account no, userID from the GUI boundary class

- Get infromation from the relevent account or user status – database connection

- Determine whether withdraw is possible – process information

9

1992-2007 Pearson Education, Inc. All rights reserved.

Entity Classes

Internal representation of entities such as – Employee

– Student

– Account

In some applications list or ArrayList of objects are hold in memory

Mirror image of database Otherwise java is a database manipulation program

– Get information from the user send it to databse or visa versa

10

1992-2007 Pearson Education, Inc. All rights reserved.

Example: taking square root of a real number

Get a real mumber from the user, take its square root and display the results in a label

Control object– Creats the bounday object

- Boundary class communicates with user When the user enters a number to the text field and press

the square rootbutton – The contrl class is invoked

Control object gets the numer in the textField prform processing by taking the square root

and send the result back to the bounday object to be displayed in a label

11

1992-2007 Pearson Education, Inc. All rights reserved.

Output of program

12

1992-2007 Pearson Education, Inc. All rights reserved.

Test class

import javax.swing.*;import java.awt.*;import java.awt.event.*;public class BoundaryControl { public static void main(String args[]) {

ControlClass control = new ControlClass();

} // end method main} // end class DoundaryControl

13

1992-2007 Pearson Education, Inc. All rights reserved.

The Control class

class ControlClass { JFrameBoundary boundary; double value;

public ControlClass() {boundary = new JFrameBoundary(this);

} // end constructor

public void buttonPressed() {

value = boundary.getValue();value = Math.sqrt(value) ;boundary.setResult(value);

} // end method buttonPressed} // end class ControlClass

14

1992-2007 Pearson Education, Inc. All rights reserved.

The Boundary class

class JFrameBoundary extends JFrame {

JTextField enterValue;JLabel result;JButton squareRoot;ControlClass controlObj;

public JFrameBounary(ControlClass ctrlObj) {controlObj = ctrlObj;setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(400, 200);

15

1992-2007 Pearson Education, Inc. All rights reserved.

The boundary class cont.

setLayout( new FlowLayout());enterValue = new JTextField(10);result = new JLabel(“”);squareRoot = new JButton(“Square Root");

add(enterValue);add(result);add(squareRoot);

Handler handler = new Handler();squareRoot.addActionListener(handler);setVisible(true);

} // end constructor

16

1992-2007 Pearson Education, Inc. All rights reserved.

İnner class Handler

private class Handler implements ActionListener { public void actionPerformed(ActionEvent e) { controlObj.buttonPressed(); } // end method actionPerformed} // end inner class Handler

public double getValue() { return Double.parseDouble(enterValue.getText());} // end method getValue

public void setResult(double x) { String s = String.format(“square root: %10.3f”,x); result.setText(s);} // end method setResult

} // end class

17

1992-2007 Pearson Education, Inc. All rights reserved.

Notes

Boundary object calls control class so the control object has to be registered to the badudaryobjec

– When a boundary is created the current control object is sent to the xFraem0 object as well so that the xFrame0 object also knows the control object.

18

1992-2007 Pearson Education, Inc. All rights reserved.

Another Approach

class ControlClass { JFrameBoundary boundary; double value;

public ControlClass() { boundary = new JFrameBoundary(this); } // end constructor

public void getValue(double x) {

value = x; value = Math.sqrt(value) ; boundary.setResult(value);

} // end method buttonPressed} // end class ControlClass

19

1992-2007 Pearson Education, Inc. All rights reserved.

The Boundary class

class JFrameBoundary extends JFrame {

JTextField enterValue;JLabel result;JButton squareRoot;ControlClass controlObj;

public JFrameBounary(ControlClass ctrlObj) {controlObj = ctrlObj;setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(400, 200);

20

1992-2007 Pearson Education, Inc. All rights reserved.

The boundary class cont.

setLayout( new FlowLayout());enterValue = new JTextField(10);result = new JLabel(“”);squareRoot = new JButton(“Square Root");

add(enterValue);add(result);add(squareRoot);

Handler handler = new Handler();squareRoot.addActionListener(handler);setVisible(true);

} // end constructor

21

1992-2007 Pearson Education, Inc. All rights reserved.

İnner class Handler

private class Handler implements ActionListener { public void actionPerformed(ActionEvent e) {

double x = Double.parseDouble(.getText());

contrlObj.getValue(x); } // end method actionPerformed} // end inner class Handler

public void setResult(doube x) { String s = String.format(“square root: %10.3f”,x); jTextFieldResult.setText(s);} // end method setResult

} // end class

22

1992-2007 Pearson Education, Inc. All rights reserved.

Example

Product selectin

23

1992-2007 Pearson Education, Inc. All rights reserved.

24

1992-2007 Pearson Education, Inc. All rights reserved.

import javax.swing.*;import java.awt.*;import java.awt.event.*;public class BoundaryControl1 {public static void main(String args[]) {

ControlClass cntrlObj= new ControlClass();

} // end method main} // end class BoundaryContro

25

1992-2007 Pearson Education, Inc. All rights reserved.

Control Class

class ControlClass { private String products[] = {"cheese","salami","tomata","ovel"}; private double prices[] = {10.5,12.25,20.75,15};

JFrameBoundary boundary;public ControlClass() {

boundary = new JFrameBoundary(this,products);

boundary.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

boundary.setSize(400, 200); boundary.setVisible(true);

} // end constructor

26

1992-2007 Pearson Education, Inc. All rights reserved.

public void itemsSelected() {double total = 5.0;int i;int selectedIng[] =

boundary.getSelectedItems();for(i=0;i<selectedIng.length;i++)

total += prices[selectedIng[i]];

boundary.setResult(total);} // end method buttonPressed

} // end class ControClass

27

1992-2007 Pearson Education, Inc. All rights reserved.

class JFrameBoundary extends JFrame {

ControlClass controlObj;

private JList list;private JButton button;private JLabel totalPrice;

public JFrameBoundary(ControlClass ctrlObj, String[] ingrad) {

controlObj = ctrlObj; ; setLayout( new FlowLayout());

28

1992-2007 Pearson Education, Inc. All rights reserved.

list = new JList(ingrad);list.setVisibleRowCount(2);

list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);button = new JButton("Selected");totalPrice = new JLabel("Total price:");

add(new JScrollPane(list));add(button);add(totalPrice);

Handler handler = new Handler();button.addActionListener(handler);

} // end constructor

29

1992-2007 Pearson Education, Inc. All rights reserved.

private class Handler implements ActionListener {public void actionPerformed(ActionEvent e) {

controlObj.itemsSelected(); } // end method actionPerformed

} // end inner class Handler

public int[] getSelectedItems() {return list.getSelectedIndices();

} // end method getSelectedItems

public void setResult(double x) {String s = String.format("Total price:%10.3f“,x); totalPrice.setText(s);

} // end method setResult

} // end class JFrameBoundary

30

1992-2007 Pearson Education, Inc. All rights reserved.

Notes

When items are selected and button is pressed The actionPerformend method’s only task is to

inform the control object that the user seleced some items and want price to be calculated.

Conrol class’s itemsSelected methd get information from the boundary wia the getSelecedItems method, calcualte total and send total to bounday class so as to be displayed in a text Field

31

1992-2007 Pearson Education, Inc. All rights reserved.

Second Approach: Control class

class ControlClass { private String products[] = {"cheese","salami","tomata","ovel"}; private double prices[] = {10.5,12.25,20.75,15};

JFrameBoundary boundary; public ControlClass() {

boundary = new JFrameBoundary(this,products);

boundary.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

boundary.setSize(400, 200); boundary.setVisible(true);

} // end constructor

32

1992-2007 Pearson Education, Inc. All rights reserved.

public void itemsSelected(int selectedIng[]) {

double total = 5.0;

for(int i=0;i<selectedIng.length;i++)

total += prices[selectedIng[i]];

boundary.setResult(total);

} // end method buttonPressed

} // end class ControlClass

33

1992-2007 Pearson Education, Inc. All rights reserved.

Boundary Class

class JFrameBoundary extends JFrame {

ControlClass controlObj;

private JList list;private JButton button;private JLabel totalPrice;

public JFrameBoundary(ControlClass ctrlObj, String[] ingrad) {

controlObj = ctrlObj; ; setLayout( new FlowLayout());

34

1992-2007 Pearson Education, Inc. All rights reserved.

list = new JList(ingrad);list.setVisibleRowCount(2);

list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);button = new JButton("Selected");totalPrice = new JLabel("Total price:");

add(new JScrollPane(list));add(button);add(totalPrice);

Handler handler = new Handler();button.addActionListener(handler);

} // end constructor

35

1992-2007 Pearson Education, Inc. All rights reserved.

private class Handler implements ActionListener {public void actionPerformed(ActionEvent e) { controlObj.itemsSelected(list.getSelectedIndices()); } // end method actionPerformed

} // end inner class Handler

public void setResult(double x) {String s = String.format("Total price:

%10.3f“,x); totalPrice.setText(s);

} // end method setResult

} // end class

36

1992-2007 Pearson Education, Inc. All rights reserved.

Notes

In the actionPerformed mehod of the boundary class seleced information is directly send to the control object.

Seleced item iist is extracted from the list and send as an argument ot the itemsSelected method of the control class

37

1992-2007 Pearson Education, Inc. All rights reserved.

An ATM Example

• The customer of a bank• Connects to her bank accounts• Select an account – a customer may have more then one

account• Perform opperations

• see balance• Deposit money• Withdraw money• Transfer money to another account• Cancel the oppertations

Using GUIs and database connections

38

1992-2007 Pearson Education, Inc. All rights reserved.

What are classss?

Classes:– ATM, customer, Account, Connection, GUI

Design principle Seperate clases

– Control classes – ATM

– Entities – customer, account, connection

– Boundry – CUI

39

1992-2007 Pearson Education, Inc. All rights reserved.

What are classss?

Frame

Connection

Account

Atm

Customer

40

1992-2007 Pearson Education, Inc. All rights reserved.

User to Atm class

The user has some request from the system– Enter PIN– Select an account– Select opperation– Enter or select amount of money to withdraw

The user should get messages from the system– Not enough oney to withdraw– The account not fount (in case of transfer)

User request taken from the GUI are sent to Atm the control class

Atm class calls the withdraw method of the account class– Send the ınformation to the GUI and the database

41

1992-2007 Pearson Education, Inc. All rights reserved.

Starting the program

When the program starts– A start frame of the ATM is presented to the user

In reality the user inserts her card – The card is identified

– Read the card number

– Search the database of customers

This is a ATM simulation – İnserting the card is represented as entering the card number

from the keypad

Then enter the PIN (Personel Indentification Number) from the keypad

42

1992-2007 Pearson Education, Inc. All rights reserved.

Starting the program (cont.)

These information is taken from the GUI is send to the Atm class

The Atm class– Connect to the database– To check whther there is such a customer– if true

- Creates a customer object – name ,…- Get the accounts information from the database- Send this to the GUI

– if false- Ask PIN several times

43

1992-2007 Pearson Education, Inc. All rights reserved.

Selection of the account

The user selects an account Account number is sent to the Atm class

– Creats the account class

– There are both saving or chacking accounts

After selecting an account – GUI changes

- On the left and right sides show the opperations

- Balance, withdraw, deposit, transfer, cancel

44

1992-2007 Pearson Education, Inc. All rights reserved.

Withdraw opperation

When the user selects withdraw– There are predetermined amounts

- 20,50,200,300, and others- Deermine the amount and send to Atm

– if the other button is clicked- Enter the amount from the keypad then press Enter button

GUI send the amout of money to be withdrawn trom the accont to the Atm class

The Atm calls – Check the balance of the account – if balacne > amount

- withdraw method of the account- Update the database- Send a message to the user

– if not - Send a message to the user

45

1992-2007 Pearson Education, Inc. All rights reserved.

Deposit opperation

Similar to withdraw Amount of money deposited is entered from the

keypad and press the Enter button No special choises are presented to the user Note this is just a simulation of the ATM

– In reality the physical amont of money is put to an envelop and inserted into the machine

– Here it is entered from the keypad

46

1992-2007 Pearson Education, Inc. All rights reserved.

Transfer of Money

Asks the user – the account number to which money will be trnsfered– And amount of money to be transferd

The prohlems are– Account mey not be found– The balnce may not be enough to meke this transfer + commussions if any

So the Atm class– Checks whether there is such an account– And balnce is greater then the money transfered– if so

- Withdraw moeny from the account- Updates the transfer account- Send a mesage to the user that tranfer is made succesfully

– İf not- Send a message to the user indicating that transfer in not succesul

47

1992-2007 Pearson Education, Inc. All rights reserved.

Cancel button

When pressed cancel the opperations ar cenceled the ATM returns to the first state

48

1992-2007 Pearson Education, Inc. All rights reserved.

GUI

A class that extends from JFrame Border layout

– North – infromation present information to the user– South – keypad– Cener – textfield and a label

- Amount of moeny, PIN.,,

– East and West – opperations of choises- Withdraw, deposit, transfer, cancel- 50,100,200, others

Keypad– All numbers are enterd from the keypad and appears in a

textField

49

1992-2007 Pearson Education, Inc. All rights reserved.

AtmTest class

public class AtmTest {

public static void main(String[] args) {

Atm atm = new Atm();

} // end method main

} // end class AtmTest

50

1992-2007 Pearson Education, Inc. All rights reserved.

The control class

Main task:– Create other objcect from other classes

- Account account, DbConnection dbconnection

- Frame frame

– interract with the boundary object – frame

– Updat the database

– Ubdate the temporary account object

51

1992-2007 Pearson Education, Inc. All rights reserved.

The control class

In its constructor:– Create the frame object – boundary class –

- Get information from teh user

- Present information to the user

– Create the database connection

Create an account

52

1992-2007 Pearson Education, Inc. All rights reserved.

The control class - Atm

class Atm {

DBConnection dbConnection; Account account; Account account2;

boolean tF; double balance; String accountNo; String name;

53

1992-2007 Pearson Education, Inc. All rights reserved.

constructor

/*

Create the frame

And database connection objects

Note in the frame object since it repeatedly calls the Atm (control) class methods there should be a reference to –atm-

setContrl(Atm a) method does this

*/

54

1992-2007 Pearson Education, Inc. All rights reserved.

constructor

public Control (){ Frame frame=new Frame();

frame.setControl(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500,400); frame.setVisible(true); dbConnection = new DBConnection();}

55

1992-2007 Pearson Education, Inc. All rights reserved.

Method getPassword

/* when the user enters a PIN from the GUI

call the method to send this information to the control class which chacks the database to see whether there is such a customer

if found returns true and

get the account infrmation from the database create an internal account object else return false*/

56

1992-2007 Pearson Education, Inc. All rights reserved.

Method getPassword

public boolean getPassword(String sifre){ tF=dbConnection.getPassword(sifre); if (tF) {

getDbBalance(); getDbAccountNo(); getDbName();}

createAccount();

return tF;}

57

1992-2007 Pearson Education, Inc. All rights reserved.

Method getPassword

/*

these methods get information from the database about the account

58

1992-2007 Pearson Education, Inc. All rights reserved.

public double getDbBalance(){

balance=Double.parseDouble(dbConnection.getInfo("miktar"));return balance;

}

public String getDbAccountNo(){

accountNo=dbConnection.getInfo("Noo");return accountNo;

}

public String getDbName(){

name=dbConnection.getInfo("soyad");return name;

}

59

1992-2007 Pearson Education, Inc. All rights reserved.

Methods getting infromation from athe internal accout object

• These methods• Creatre teh account object

• Get its instance variables• AccountNo

• Account name

• And balance

• And store in contol object to be used

60

1992-2007 Pearson Education, Inc. All rights reserved.

public void createAccount(){

account = new Account (name,accountNo,balance);

}

public double getBalance(){

return account.getBalance();}

public String getAccountNo(){

return account.getAccountNo();}

public String getName(){

return account.getAccountName();}

61

1992-2007 Pearson Education, Inc. All rights reserved.

Withdraw and deposit methods

First updata accont object in memory For withdraw

– if true – enough money in the account – – updata the database– return true to the caller– else – not enough money in the account– no connection to the database is needed– return false

For deposit– Updata the account object and database respectively

62

1992-2007 Pearson Education, Inc. All rights reserved.

public boolean withdraw(double amount){

if(account.withdraw(amount)){

dbConnection.dbBalanceUpdate(account.getAccountNo(), account.getBalance());

return true;}return false;

}

public void deposit(double amount){

account.deposit(amount);

dbConnection.dbBalanceUpdate(account.getAccountNo(),account.getBalance());}

63

1992-2007 Pearson Education, Inc. All rights reserved.

The Account class

• An Account class having• İnstance variables

• Balnce

• Name

• Account No

• Constructor to set these variables

• Withdraw and deposit methods

• get methods

• set methods are not wtitten yet

64

1992-2007 Pearson Education, Inc. All rights reserved.

class Account { private String name; private String accountNo; private double balance; Account(String name,String accountNo, double money){ this.name=name;

this.accountNo=accountNo; balance=money; }

65

1992-2007 Pearson Education, Inc. All rights reserved.

public void deposit( double amount ) { balance += amount;

}

public boolean withdraw( double amount ){ if (balance >= amount) {

balance -= amount;return true;

} return false;

}

66

1992-2007 Pearson Education, Inc. All rights reserved.

public String getAccountNo() { return accountNo; } public String getAccountName() { return name; } public double getBalance(){

return balance; }

} // end class Account

67

1992-2007 Pearson Education, Inc. All rights reserved.

Connection Class - DBConnection

Methods– public boolean getPassword(String sifre)

- İf the sifre is found in the databses return true

– public String getInfo(String variable)- After sifre is found - customer is found in the databse

- Get information and return to the control class

- Variable can be: miktar, Noo, soyad

– public void dbBalanceUpdate(String AccountNo,double balance)

- When money is deposited or withdrawn update the account in the database

68

1992-2007 Pearson Education, Inc. All rights reserved.

The Frame class

Define – Define a state variable

- “”, deposit, withdraw,…

– Panels– Buttons– No layout – coordinates of components are given– Add compontets to panels– Adjust visibility of panels– Register components to listeners– İmplements ActionListener as an inner class

- actionPerformed method - actionEvent

69

1992-2007 Pearson Education, Inc. All rights reserved.

Setcontrol method Called from the atm – control class Sets the referance of the control object in Frame

class as frame object calls atm object very often– a referenc is needed

70

1992-2007 Pearson Education, Inc. All rights reserved.

71

1992-2007 Pearson Education, Inc. All rights reserved.

72

1992-2007 Pearson Education, Inc. All rights reserved.

73

1992-2007 Pearson Education, Inc. All rights reserved.

74

1992-2007 Pearson Education, Inc. All rights reserved.

75

1992-2007 Pearson Education, Inc. All rights reserved.

76

1992-2007 Pearson Education, Inc. All rights reserved.

77

1992-2007 Pearson Education, Inc. All rights reserved.

Registering Action event

For all the buttons – JButton objects

An inner class implementing ActionListener intrface is registeed using the addActionListener method

78

1992-2007 Pearson Education, Inc. All rights reserved.

Registering Action event

login.addActionListener(handler);cancel.addActionListener(handler);showBalance.addActionListener(handler);withdraw.addActionListener(handler);deposit.addActionListener(handler);exit.addActionListener(handler);button5.addActionListener(handler);button10.addActionListener(handler);button20.addActionListener(handler);button50.addActionListener(handler);button100.addActionListener(handler);button250.addActionListener(handler);leftcancel.addActionListener(handler);rightOther.addActionListener(handler);okButton.addActionListener(handler);cancelButton.addActionListener(h

79

1992-2007 Pearson Education, Inc. All rights reserved.

ActionPerformed method

•All the events are action events•The method cheks the source of the event • Array of

80

1992-2007 Pearson Education, Inc. All rights reserved.

When one number buttons is clicked on the keypad

for (int i = 0; i < keyPadButton.length; i++)

{if (event.getSource() ==

keyPadButton[i]){

password = password + i;passwordd = passwordd + "*";

}

txtEnterPassword.setText(passwordd);//txtwithdraw.setText(password);

}

81

1992-2007 Pearson Education, Inc. All rights reserved.

When right pannel is

if (event.getSource() == leftcancel){

balancePanel.setVisible(false);leftPanel.setVisible(true);rightPanel.setVisible(true);withdrawLeftPanel.setVisible(false);

withdrawPanel.setVisible(false);keyPadPane.setVisible(false);confirmationPanel.setVisible(false);

withdrawRightPanel.setVisible(false);strAmount = "";txtwithdraw.setText(strAmount);intAmount = 0;

}

82

1992-2007 Pearson Education, Inc. All rights reserved.

Withdraw is clicked

if (event.getSource() == withdraw){

balancePanel.setVisible(false);leftPanel.setVisible(false);rightPanel.setVisible(false);withdrawLeftPanel.setVisible(true);

withdrawRightPanel.setVisible(true);

moneyMessage.setVisible(false);withdrawPanel.setVisible(false);

confirmationPanel.setVisible(false);keyPadPane.setVisible(false);

}

83

1992-2007 Pearson Education, Inc. All rights reserved.

Withdrawing money

The user can select one of the butons– 5,10,20,50,100,250

– Call the withdraw method of the control object

– if true – oppertation is succesful

– Write an appropriate message to the user

– No physical money is given to the user

Or select other– The amount of money to be witdrawn is asked

– Prepare the screen so that the user can enter any amount from the keypad

84

1992-2007 Pearson Education, Inc. All rights reserved.

if (event.getSource() == button5) {

if (control.withdraw(5))

lblmoneyMessage.setText("Please Get Your Money"); else

lblmoneyMessage.setText("You do not have enough money in your account");

moneyMessage.setVisible(true);} // end if 5

85

1992-2007 Pearson Education, Inc. All rights reserved.

if (event.getSource() == rightOther)

{

passwordd = "";

state = "withdraw";

withdrawPanel.setVisible(true);

keyPadPane.setVisible(true);

confirmationPanel.setVisible(true);

}

86

1992-2007 Pearson Education, Inc. All rights reserved.

Depositing money

•If the user click deposit•The screen is prepaired for dopositnig money• Keypad • Texfield for entering moeny is shown to the user

• Stare is set to deposit

87

1992-2007 Pearson Education, Inc. All rights reserved.

if (event.getSource() == deposit){

password = "";state = "deposit";withdrawPanel.setVisible(true);keyPadPane.setVisible(true);

confirmationPanel.setVisible(true);}

88

1992-2007 Pearson Education, Inc. All rights reserved.

Ok button

When the ok button is clicked

The resutlts depends on the state

Whether state is deposit or withdraw

89

1992-2007 Pearson Education, Inc. All rights reserved.

if (event.getSource() == okButton){

if (password != "")

if (state.equals("withdraw")){

intAmount = Integer.parseInt(password);

if (control.withdraw(intAmount))

lblmoneyMessage.setText("Please Get Your Money...");else

lblmoneyMessage.setText("You do not have enough money in your account");moneyMessage.setVisible(true);

withdrawPanel.setVisible(false);keyPadPane.setVisible(false);

confirmationPanel.setVisible(false);}

90

1992-2007 Pearson Education, Inc. All rights reserved.

if (state.equals("deposit")){

if (password != ""){

intAmount = Integer.parseInt(password);

control.deposit(intAmount);lblmoneyMessage.setText("Your

Money Has Been Deposited");

moneyMessage.setVisible(true);

withdrawPanel.setVisible(false);keyPadPane.setVisible(false);

confirmationPanel.setVisible(false);}

}}

91

1992-2007 Pearson Education, Inc. All rights reserved.

cancel

if (event.getSource() == cancelButton)

{password = "";state = "";accountPanel.setVisible(false);

withdrawPanel.setVisible(false);keyPadPane.setVisible(false);

confirmationPanel.setVisible(false);

}

92

1992-2007 Pearson Education, Inc. All rights reserved.

Exit

Return to the first screen Change the state to “” Adjust the visibility of panels Set the String and numerical variables to ** or

zero

93

1992-2007 Pearson Education, Inc. All rights reserved.

if (event.getSource() == exit){

keyPadPane.setVisible(true);enterPane.setVisible(true);leftPanel.setVisible(false);rightPanel.setVisible(false);accountPanel.setVisible(false);balancePanel.setVisible(false);

withdrawLeftPanel.setVisible(false);

withdrawRightPanel.setVisible(false);withdrawPanel.setVisible(false);

confirmationPanel.setVisible(false);

94

1992-2007 Pearson Education, Inc. All rights reserved.

password = ""; passwordd = "";

txtEnterPassword.setText(passwordd);

txtwithdraw.setText(password);

state = ""; balanceamount = 0;

intAmount = 0; strAmount = "";} // end if for exit