atm_client.java
来自「简单ATM(Automatic Teller Machine)系统的基本功能包括」· Java 代码 · 共 544 行 · 第 1/2 页
JAVA
544 行
Label account=new Label("您的余额为:");
TextField tx3=new TextField(15);
tx3.setText(""+balance);
plOperate.add(account);
plOperate.add(tx3);
winOperate.setVisible(true);
return;
}
}
}
dialogErr.setVisible(true);
} catch (Exception ex) {
//System.out.println(ex.toString());
}
}
//type=0表示取款,type=1表示存款
public void updateBalance(String moneyStr,int type)
{
try {
String msg;
//check moneyStr
if (Msg.isValid(moneyStr, moneyStr.length())
&& Integer.parseInt(moneyStr)>0
&& Integer.parseInt(moneyStr)<=2000)
{
if (type == 0)
msg = Character.toString(Msg.CMD_WITHDROW) + moneyStr;
else
msg = Character.toString(Msg.CMD_DEPOSIT) + moneyStr;
out.println(msg);
String line;
if ((line = is.readLine()) != null) {
System.out.println("Received: "+line);
char cmd = line.charAt(0);
if (cmd == Msg.CMD_WITHDROW || cmd == Msg.CMD_DEPOSIT) {
char result = line.charAt(1);
if (result == Msg.SUCCESSFUL) { //登录成功
plOperate.removeAll();
Label money1 = new Label("交易成功");
plOperate.add(money1);
winOperate.setVisible(true);
return;
}
}
}
}
dialogErr.setVisible(true);
} catch (Exception ex) {
//System.out.println("error" + ex.toString());
}
}
public void updatePassword(String newPwd)
{
try {
//check account and password
if (Msg.isValid(newPwd, Msg.PWD_LENGTH))
{
String msg=Character.toString(Msg.CMD_CHANGE)+ newPwd;
out.println(msg);
String line;
if ((line = is.readLine()) != null) {
System.out.println("Received: "+line);
char cmd = line.charAt(0);
if (cmd == Msg.CMD_CHANGE) {
char result = line.charAt(1);
if (result == Msg.SUCCESSFUL) { //登录成功
plOperate.removeAll();
Label pass1 = new Label("密码修改成功");
plOperate.add(pass1);
winOperate.setVisible(true);
return;
}
}
}
}
dialogErr.setVisible(true);
} catch (Exception ex) {
//System.out.println(ex.toString());
}
}
class ActionListener1 implements ActionListener
{
int moneyInt,password1;
Button btnWithdrawOK,btnDepositOK,btnChageOK;
String moneyStr,newPwdStr;
TextField tfMoney,tfNewPwd;
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==fileMenuItem1)
{
exitPro();
//System.exit(0);
}
if(e.getSource()==helpMenuItem1)
{
dialogAbout.setSize(220,100);
dialogAbout.setVisible(true);
//dialogAbout.addWindowListener(new WindowListener2());
}
if(e.getSource()==btnExit)
{
if(flag==true)
{
plOperate.removeAll();
winOperate.dispose();
new ATM_client();
}
}
if(e.getSource()==btnCancel)
{
tfUser.setText("");
tfPwd.setText("");
}
if(e.getSource()==btnLogin)
{
username=tfUser.getText();
//password=Integer.parseInt(tfPwd.getText());
password=tfPwd.getText();
login(username,password);
}
if(e.getSource()==btnBalance)
{
plOperate.removeAll();
queryBalance();
}
if(e.getSource()==btnWithdraw || e.getSource()==btnDeposit)
{
if(flag==true)
{
Label lblMoney;
plOperate.removeAll();
if(e.getSource()==btnWithdraw)
{
lblMoney = new Label("取款金额:");
btnWithdrawOK = new Button("OK");
btnWithdrawOK.addActionListener(new
ActionListener2());
}
else{
lblMoney = new Label("存款金额:");
btnDepositOK = new Button("OK");
btnDepositOK.addActionListener(new
ActionListener2());
}
tfMoney=new TextField(10);
plOperate.add(lblMoney);
plOperate.add(tfMoney);
if(e.getSource()==btnWithdraw)
plOperate.add(btnWithdrawOK);
else
plOperate.add(btnDepositOK);
winOperate.setVisible(true);
}
}
if(e.getSource()==btnChange)
{
if(flag==true)
{
plOperate.removeAll();
Label lblNewPwd=new Label("输入新密码:");
tfNewPwd=new TextField(10);
tfNewPwd.setColumns(6);
tfNewPwd.setEchoChar('*');
plOperate.add(lblNewPwd);
plOperate.add(tfNewPwd);
btnChageOK=new Button("OK");
btnChageOK.addActionListener(new ActionListener2());
plOperate.add(btnChageOK);
winOperate.setVisible(true);
}
}
}
class ActionListener2 implements ActionListener
{
public void actionPerformed(ActionEvent ee)
{
//System.out.println(moneyInt);
if(ee.getSource()==btnWithdrawOK)
{
moneyStr=tfMoney.getText();
//updateBalance(Integer.parseInt(moneyStr));
updateBalance(moneyStr,0);
}
if(ee.getSource()==btnDepositOK)
{
moneyStr=tfMoney.getText();
updateBalance(moneyStr,1);
}
if(ee.getSource()==btnChageOK)
{
newPwdStr=tfNewPwd.getText();
//updatePassword(Integer.parseInt(newPwdStr));
updatePassword(newPwdStr);
}
}
}
}
class MyDialog extends Dialog
{
Label label2=new Label("Author:梁 文 ");
Label label3=new Label("Email:liangwen_215@yahoo.com.cn");
MyDialog(Frame frame1,String title,boolean bool)
{
super(frame1,title,bool);
BorderLayout layout=new BorderLayout();
setLayout(layout);
add(label2,BorderLayout.CENTER);
add(label3,BorderLayout.SOUTH);
}
}
}
//-----------------------------------------------------------
class Logo extends JWindow implements Runnable
{
String filename;
public Logo(String name)
{
filename=name;
}
public Logo()
{
}
public void run()
{
URL imgURL = getClass().getResource(filename);
ImageIcon ig=new ImageIcon(imgURL);
JButton btnOK=new JButton(ig);
getContentPane().add(btnOK);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
setLocation(screenSize.width/8,screenSize.height/8);
setSize(ig.getIconWidth(),ig.getIconHeight());
toFront();
thread1 thread2=new thread1();
thread2.start();
//setVisible(false);
}
public void setNotVisible()
{
setVisible(false);
}
class thread1 extends Thread
{
public void run()
{
try
{
setVisible(true);
sleep(4000);
setNotVisible();
}
catch(InterruptedException e)
{
//System.out.print(e.toString());
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?