天天看點

java atm程式設計_Java ATM機操作界面程式哦

Java ATM機操作界面程式哦

//以下是我寫的ATM操作界面的程式//

//請高手賜教如何添加背景圖形????//

import java.awt.*;

import java.awt.event.*;

public class AtmDialog

{

public static void main(String args[])

{

MyDialogFrame df=new MyDialogFrame();

}

}

class MyDialogFrame extends Frame

implements ActionListener,ComponentListener

{

Dialog MegDlg,InOutDlg;

Label prompt;

Label prompt1;

Button btn1,btn2,btn3,btn4,btn5;

TextField tf=new TextField("請按相關按鈕操作",25);

TextField getMeg=new TextField("您目前的存款是1000元. 2004-11-22",10);

TextField getMeg1=new TextField(20);

MyDialogFrame()

{

super("ATM終端");

prompt=new Label("歡迎您的光臨!");

btn1=new Button("取款");

btn2=new Button("查詢");

btn3=new Button("确定");

btn4=new Button("取消");

btn5=new Button("傳回");

setLayout(new FlowLayout());

add(prompt);

add(tf);

add(btn1);

add(btn2);

//add(btn3);

//btn1.addComponentListener(this);

getMeg1.addActionListener(this);

btn1.addActionListener(this);

btn2.addActionListener(this);

//btn3.addActionListener(this);

btn3.addActionListener(this);

btn4.addActionListener(this);

btn5.addActionListener(this);

setSize(350,150);

show();

}

public void actionPerformed(ActionEvent e)

{

if(e.getActionCommand()=="取款")

{

MegDlg=new Dialog(this,"請輸入取款金額",true);

Panel p1=new Panel();

MegDlg.add("Center",getMeg1);

Panel p2=new Panel();

p2.add(btn3);

p2.add(btn4);

MegDlg.add("South",p2);

MegDlg.setSize(200,100);

MegDlg.show();

}

else if(e.getActionCommand()=="查詢")

{

InOutDlg=new Dialog(this);

InOutDlg.add("Center",getMeg);

InOutDlg.add("South",btn5);

InOutDlg.setSize(200,100);

InOutDlg.show();

}

else if(e.getActionCommand()=="确定")

{

tf.setText("請取走金額...");

getMeg.setText("您的帳戶餘額為:(1000-"+getMeg1.getText()+")元");

MegDlg.dispose();

}

// else if(getMeg1.getText()

else if(e.getActionCommand()=="取消")

MegDlg.dispose();

else if(e.getActionCommand()=="傳回")

{

InOutDlg.dispose();

}

}

public void componentShown(ComponentEvent e){}

public void componentResized(ComponentEvent e){}

public void componentMoved(ComponentEvent e){}

public void componentHidden(ComponentEvent e){}

}

class WinAdpt extends WindowAdapter

{

public void windowClosing(WindowEvent e)

{

((Frame)e.getWindow()).dispose();

System.exit(0);

}

}