?? display.java
字號:
/*-------------------- ATM存取款模擬Java實現-----------------------
*--------------------- Develop by PopStu Studio.------------------
* ---------------------@version 1.0-------------------------------
* ---------------------@author CrossLife--------------------------
*---------------------------2007.12-------------------------------
*/
import java.sql.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class display implements ActionListener
{
Frame fram;
Panel Pnlwel,Pnlinput,PnlMenu,PnlGetmoney,Pnlputmoney,PnlQueryleft,PnlChgpwd,PnlMsg;
Button btnwel,btnimp,a1,a2,a3,a4,a5,quit,b1,b2,b3,b4,b5,b6,back,dok,btnpmy;
Button x1,y1,b7,b8,c1,c2,y2,d1,d2,y3,p1,p,d3;
Label msgstr,msghint,msg3,lbleft,lblMsg;
TextField Usetext,oldpwd,newpwd1,newpwd2;
CardLayout CardOut=new CardLayout();//系統界面布局方式
float UserMoney=0,TodayMoney=0;
int nstate=0,num=0;//判別多個狀態nstate: 1、修改密碼;2、數據輸入;3、菜單 num:0。無用戶登陸 1.有用戶登陸 2.改卡已經被鎖
String CardID,pwd;
Account Useact=new Account();
moneyMachine mce=new moneyMachine();
PutmoneyMachine pmce=new PutmoneyMachine();
readCard UseRCard=new readCard();
dataSQL Usedata=new dataSQL();
public void mainFram()
{
fram=new Frame("中國銀行歡迎你!");
quit=new Button("退出");
back=new Button("返回");
back.addActionListener(this);
quit.addActionListener(this);
this.showChangePwd();
this.showGetMoney();
//this.showPutMoney();
this.showHint();
this.showMenu();
this.showQueryLeft();
this.showWelcome();
this.showInput();
fram.setLayout(CardOut);
fram.add(Pnlwel,"wel");
fram.add(Pnlinput,"input");
fram.add(PnlMenu,"Menu");
fram.add(PnlChgpwd,"Chgpwd");
fram.add(PnlGetmoney,"Getmoney");
//fram.add(Pnlputmoney,"Putmoney");
fram.add(PnlQueryleft,"Queryleft");
fram.add(PnlMsg,"Msg");
fram.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
fram.setSize(600,400);
fram.setLocation(600,300);
fram.setVisible(true);
}
public void showWelcome()
{
Pnlwel=new Panel();
GridLayout gdo1=new GridLayout(5,3,10,10);
Label xlbl1=new Label("歡迎使用ATM自助系統,本系統24小時提供服務!");
xlbl1.setAlignment(Label.CENTER);
Label wart=new Label("單次交易金額不能超過5000,每天最高交易金額為5000!");
wart.setAlignment(Label.CENTER);
Label wart1=new Label("3次密碼輸入錯誤將會鎖定你的卡,請謹慎輸入!鎖卡請聯系發卡行解鎖。如出現無故吞卡請電話95599");
wart1.setAlignment(Label.CENTER);
btnwel=new Button("進入");
x1=new Button("退出");
btnwel.addActionListener(this);
x1.addActionListener(this);
Panel xpnl=new Panel();
xpnl.add(btnwel);xpnl.add(x1);
Pnlwel.setLayout(gdo1);
Pnlwel.add(xlbl1);
Pnlwel.add(wart);
Pnlwel.add(wart1);
Pnlwel.add(xpnl);
}
public void showInput()
{
Pnlinput=new Panel();
GridLayout gdo2=new GridLayout(4,3,10,10);
msgstr=new Label("請輸入您的卡號:");
msghint=new Label("");
Usetext=new TextField("",30);
btnimp=new Button("確定");
btnimp.addActionListener(this);
y1=new Button("退出");
y1.addActionListener(this);
y2=new Button("返回");
y2.addActionListener(this);
y2.setVisible(false);
y3=new Button("返回");
y3.addActionListener(this);
y3.setVisible(false);
Panel spnl1=new Panel();
spnl1.setLayout(new BorderLayout());
spnl1.add(Usetext,BorderLayout.NORTH);
spnl1.add(msghint,BorderLayout.SOUTH);
Panel spnl2=new Panel();
spnl2.add(btnimp); spnl2.add(y2);spnl2.add(y3); spnl2.add(y1);
Pnlinput.setLayout(gdo2);
Pnlinput.add(msgstr);
Pnlinput.add(spnl1);
Pnlinput.add(spnl2);
}
public void showMenu()
{
PnlMenu=new Panel();
GridLayout gdo3=new GridLayout(6,1);
Label albl=new Label("請選擇業務");
//albl.setBackground(Color.blue);
albl.setAlignment(Label.CENTER);
a1=new Button("1、取款"); a2=new Button("2、余額查詢");
a3=new Button("3、修改密碼"); a4=new Button("4、存款");
a5=new Button("5、退出");
a1.addActionListener(this); a3.addActionListener(this);
a2.addActionListener(this); a4.addActionListener(this);
a5.addActionListener(this);
PnlMenu.setLayout(gdo3);
PnlMenu.add(albl); PnlMenu.add(a1);
PnlMenu.add(a2); PnlMenu.add(a3);
PnlMenu.add(a4); PnlMenu.add(a5);
}
public void showGetMoney()
{
PnlGetmoney=new Panel();
GridLayout gdo4=new GridLayout(4,4);
PnlGetmoney.setLayout(new BorderLayout());
Label blbl=new Label("請選擇取款金額");
msg3=new Label("");
b1=new Button("100"); b2=new Button("300");
b3=new Button("500");b4=new Button("800");
b5=new Button("1000");b6=new Button("其他");
b1.addActionListener(this); b5.addActionListener(this);
b2.addActionListener(this); b6.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b7=new Button("返回");
b7.addActionListener(this);
b8=new Button("退出");
b8.addActionListener(this);
Panel bpnl1=new Panel();
bpnl1.add(blbl);
Panel bpnl3=new Panel();
bpnl3.add(b7); bpnl3.add(b8);
Panel bpnl2=new Panel();
bpnl2.setLayout(gdo4);
bpnl2.add(b1); bpnl2.add(new Label()); bpnl2.add(b4);
bpnl2.add(b2); bpnl2.add(msg3); bpnl2.add(b5);
bpnl2.add(b3); bpnl2.add(new Label()); bpnl2.add(b6);
bpnl2.add(new Label()); bpnl2.add(bpnl3); bpnl2.add(new Label());
PnlGetmoney.add(bpnl1,BorderLayout.NORTH);
PnlGetmoney.add(bpnl2,BorderLayout.CENTER);
}
public void showQueryLeft()
{
PnlQueryleft=new Panel();
PnlQueryleft.setLayout(new BorderLayout());
Label clbl=new Label("帳戶余額");
clbl.setAlignment(Label.CENTER);
lbleft=new Label("");
Panel cpnl1=new Panel();
cpnl1.add(lbleft);
Panel cpnl2=new Panel();
c1=new Button("返回");
c1.addActionListener(this);
c2=new Button("退出");
c2.addActionListener(this);
//cpnl2.add(edok);Button edok=new Button("確定");
cpnl2.add(c1); cpnl2.add(c2);
PnlQueryleft.add(clbl,BorderLayout.NORTH);
PnlQueryleft.add(cpnl1,BorderLayout.CENTER);
PnlQueryleft.add(cpnl2,BorderLayout.SOUTH);
}
public void showChangePwd()
{
PnlChgpwd=new Panel();
GridLayout gdo6=new GridLayout(5,1);
PnlChgpwd.setLayout(gdo6);
Label dlbl1=new Label("修改密碼");
dlbl1.setAlignment(Label.CENTER);
Label dlbl2=new Label("請輸入原密碼:");
Label dlbl3=new Label("請輸入新密碼:");
Label dlbl4=new Label("請再輸入新密碼:");
dok=new Button("確定");
dok.addActionListener(this);
oldpwd=new TextField(15); newpwd1=new TextField(15); newpwd2=new TextField(15);
oldpwd.setEchoChar('*'); newpwd1.setEchoChar('*'); newpwd2.setEchoChar('*');
d3=new Button("清空");
d3.addActionListener(this);
d1=new Button("返回");
d1.addActionListener(this);
d2=new Button("退出");
d2.addActionListener(this);
Panel dpnl1=new Panel();
Panel dpnl2=new Panel();
Panel dpnl3=new Panel();
Panel dpnl4=new Panel();
Panel dpnl5=new Panel();
dpnl1.add(dlbl1);
dpnl2.add(dlbl2); dpnl2.add(oldpwd);
dpnl3.add(dlbl3); dpnl3.add(newpwd1);
dpnl4.add(dlbl4); dpnl4.add(newpwd2);
dpnl5.add(dok); dpnl5.add(d3); dpnl5.add(d1); dpnl5.add(d2);
PnlChgpwd.add(dpnl1); PnlChgpwd.add(dpnl2);
PnlChgpwd.add(dpnl3); PnlChgpwd.add(dpnl4);
PnlChgpwd.add(dpnl5);
}
public void showHint()
{
PnlMsg=new Panel();
PnlMsg.setLayout(new BorderLayout());
Label elbl=new Label("系統提示");
elbl.setAlignment(Label.CENTER);
lblMsg=new Label("");
Panel epnl=new Panel();
epnl.add(lblMsg);
Panel epnl2=new Panel();
epnl2.add(back); epnl2.add(quit);
PnlMsg.add(elbl,BorderLayout.NORTH);
PnlMsg.add(epnl,BorderLayout.CENTER);
PnlMsg.add(epnl2,BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnwel)//進入輸入界面
{
CardOut.show(fram,"input");
Usetext.setFocusable(true);
}
if(e.getSource()==btnimp)//包含用戶ID、密碼和取款金額的驗證等操作
{
if((msgstr.getText().indexOf("卡號"))>0)//用戶ID驗證
{
if (Usetext.getText().length()!=18)
{
msghint.setText("你輸入的銀行帳戶錯誤,正確的銀行帳戶是18位,請檢查后重新輸入!!");
Usetext.setText("");//清除輸入框中數據
Usedata.sleep(2);
msghint.setText("");
}
else if (!Useact.isNumeric(Usetext.getText()))
{
msghint.setText("你輸入的銀行帳戶錯誤,正確的銀行帳戶是18位數字,請檢查后重新輸入!!");
Usetext.setText("");//清除輸入框中數據
Usedata.sleep(2);
msghint.setText("");
}
else{
if(!Useact.checkAccount(UseRCard.getCardID(Usetext.getText())))
{
msghint.setText("你輸入的銀行帳戶不存在,請重新輸入!!");
Usetext.setText("");//清除輸入框中數據
Usedata.sleep(2);
msghint.setText("");
}
else if(Useact.queryCard(UseRCard.getCardID(Usetext.getText()))==1)
{
msghint.setText("對不起,你的卡已經在別的地方登陸,請稍后再試!!!");
Usetext.setText("");
Usedata.sleep(2);
msghint.setText("");
}
else if(Useact.queryCard(UseRCard.getCardID(Usetext.getText()))==2)
{
msghint.setText("對不起,你的卡已經被鎖定,請聯系發卡銀行!!!");
Usetext.setText("");
Usedata.sleep(2);
msghint.setText("");
}
else
{
Usetext.setEchoChar('*');
msgstr.setText("請輸入密碼:");
this.CardID=Usetext.getText();
Usetext.setText("");
Useact.checkCardID(CardID,1);
}
}
return;
}
if((msgstr.getText().indexOf("存款金額"))>0)//手動輸入存款金額
{
try
{
UserMoney=Float.parseFloat(Usetext.getText());
if (UserMoney<=0)
{
lblMsg.setText("您輸入的金額錯誤,存款金額不能為負!!!");
nstate=3;
}
else{
if(UserMoney%50==0){
if(Useact.addMoney(CardID,UserMoney))
{
lblMsg.setText(pmce.printBill(UserMoney,CardID,Useact.queryBalance(CardID)));
nstate=3;
}
}
else {
lblMsg.setText("存款金額只能為50的倍數!!!");
nstate=3; }}}
catch(NumberFormatException e2)//輸入非法的金額
{
lblMsg.setText("您輸入的金額錯誤!!!");
nstate=2;
}
finally
{
CardOut.show(fram,"Msg");
return;
}
}
if((msgstr.getText().indexOf("密碼"))>0)//密碼驗證操作
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -