//以下是我写的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()<getMeg.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); } }