import java.applet.*;import java.awt.*;public class ATM extends Applet{	private final int	START_MODE = 0,							DEPOSIT_MODE = 1,							WITHDRAW_MODE = 2;	private int mode;		private TextField	display = new TextField();	private Keypad	pad = new Keypad();	private Button	clear = new Button("Clear"),						enter = new Button("Enter"),						deposit = new Button("Deposit"),						withdraw = new Button("Withdraw");	private TextArea	help = new TextArea(6, 18);		public void init()	{		Panel p1 = new Panel();		p1.setLayout(new GridLayout(4, 1, 0, 3));		p1.add(clear);		p1.add(enter);		p1.add(deposit);		p1.add(withdraw);				Panel p2 = new Panel();		p2.setLayout(new BorderLayout(3, 0));		p2.add("Center", pad);		p2.add("East", p1);				Panel p3 = new Panel();		p3.setLayout(new BorderLayout());		p3.add("North", display);		p3.add("Center", p2);				this.setLayout(new BorderLayout(5, 5));		this.add("Center", p3);		this.add("East", help);		this.setBackground(Color.lightGray);		this.resize(325, 150);				introStart();	}		public boolean action(Event e, Object obj)	{		switch (mode)		{		case START_MODE:			if (e.target == deposit)				introDeposit();			else if (e.target == withdraw)				introWithdraw();			else if (e.target == clear)				// LATER			return true;		case DEPOSIT_MODE:			if (e.target == enter)				handleDeposit();			else if (e.target == clear)				display.setText("");			else if (e.target == pad)				// LATER			return true;		case WITHDRAW_MODE:			if (e.target == enter)				handleWithdrawal();			else if (e.target == clear)				display.setText("");			else if (e.target == pad)				// LATER			return true;		}		return false;	}		private void introStart()	{		help.setText("         W E L C O M E\n\n");		help.appendText("Press the Deposit or Withdraw buttons ");		help.appendText("to make a transaction.\n\n");		help.appendText("Press Clear to end this session.");				mode = START_MODE;		enter.disable();		deposit.enable();		withdraw.enable();	}		private void introDeposit()	{		help.setText("           D E P O S I T\n\n");		help.appendText("Key in the amount of your deposit ");		help.appendText("and then press Enter to finish.\n\n");		help.appendText("If you make a mistake, press Clear, ");		help.appendText("key in your deposit again, ");		help.appendText("and then press Enter. ");				mode = DEPOSIT_MODE;		enter.enable();		deposit.disable();		withdraw.disable();	}		private void introWithdraw()	{		help.setText("         W I T H D R A W A L\n\n");		help.appendText("Key in the amount of your withdrawal ");		help.appendText("and then press Enter to finish.\n\n");		help.appendText("If you make a mistake, press Clear, ");		help.appendText("key in your withdrawal again, ");		help.appendText("and then press Enter. ");				mode = WITHDRAW_MODE;		enter.enable();		deposit.disable();		withdraw.disable();	}		private void handleDeposit()	// A deposit request has been made.  Check whether the amount in	// display is nonzero.  If so, just go back to start mode.  If not,	// display a help message.	{		introStart();	}		private void handleWithdrawal()	// A withdrawal request has been made.  Check whether the amount in	// display is nonzero.  If so, just go back to start mode.  If not,	// display a help message.	{		introStart();	}}//-------------------------------------------------------------class Keypad extends Panel{	private Button	b0 = new Button("0"),						b1 = new Button("1"),						b2 = new Button("2"),						b3 = new Button("3"),						b4 = new Button("4"),						b5 = new Button("5"),						b6 = new Button("6"),						b7 = new Button("7"),						b8 = new Button("8"),						b9 = new Button("9"),						bPoint = new Button(".");		public Keypad()	{		setLayout(new GridLayout(4, 3, 2, 2));		add(b7);		add(b8);		add(b9);		add(b4);		add(b5);		add(b6);		add(b1);		add(b2);		add(b3);		add(b0);		add(bPoint);	}}