《C/S项目实训》
课程设计报告
题 目: ATM模拟银行
学生姓名(学号): 代小龙(20***1)安梓玮(20***7)侯硕(20***5)
专 业: 信息管理与信息系统
班 级: 18信管(一)班
指导教师: 申晨
信息管理与工程系
2019年01月02日
基于Java的ATM模拟银行开发与设计
摘要:
自动取款机又称ATM,意思是自动柜员机,因大部分用于取款,又称自动取款机。它是一种利用磁性代码卡或智能卡实现金融交易的自助服务,代替银行柜面人员的工作。可提取现金、查询存款余额、进行账户之间资金转账、余额查询等工作;还可以进行现金存款(实时入账)、中间业务等工作。持卡人可以根据密码办理自动取款、查询余额、转账、现金存款,更改密码,缴纳手机话费等业务。我们在这次课程设计上运用了JAVA以及 SQL Server 2012进行设计。.该系统是站在用户的角度来实现取款,存款,转账,修改密码,定期存款,查询余额多个页面的实现,页面的实现满足了银行基本的业务需求,使银行工作规范化,自动化,在系统页面设计方面,我们使得系统的功能操作简单,用户体验较好。
窗体底端
关键字:ATM模拟机,用户,管理员,页面设计,JAVA,sql server,Eclipse集成开发环境下开发系统
目 录 项目简介与分工 1
1.1 项目简介 1
1.1.1 系统开发需求 1
1.1.2系统具体事务 1
1.1.3 系统开发环境要求 1
1.2 项目分工 2 项目设计方案 3 项目功能实现 4
3.1数据库的实现 4
3.2主要功能实现 5
3.2.1主界面 5
3.2.2普通用户存款界面 9
3.2.3用户转账 11
3.2.4手机缴费 16
3.2.5用户取款 19
3.2.6冻结 24
3.2.7开户 26
3.2.8销户 30项目总结及展望 33 心得体会 34
参 考 文 献 35 项目简介与分工
1.1 项目简介
本系统采用JAVA语言编写测试完成,基本上在字符界面下模拟了ATM系统的相关实现。主要模拟银行ATM机系统功能,主要有查阅、转账、取款、存款、添加用户、删除用户、修改密码、冻结用户,管理员解冻、手动手机费缴费等功能
1.1.1 系统开发需求
随着市场经济的发展,经济信息化程度的不断深入,银行的传统业务己愈来
愈不能满足银行客户的需要。同时,随着国内银行机构的大量增加,我国的银行业面临更加激烈的同业竞争,如何提供更多的金融产品和更优质的服务,如何吸引更多的客户,如何利用计算机技术加强银行帐户信息管理,提高银行的工作效率和业务竟争能力是摆在各家银行面前的一个迫切需要解诀的问题。随着信息技术对银行业的渗透和促进,银行卡业务近年来得到“迅猛发展,银行卡发卡量、交易量大幅激增,ATM设备数量也随之增加。
1.1.2系统具体事务
用户:用户存款、取款、转账、余额信息查询、修改密码、手机话费的缴费并与数据库实时同步。
管理员:对用户账号的冻结以及解冻并询问是否修改密码、开户与销户、与数据库实时同步。
1.1.3 系统开发环境要求.操作系统:Windows系统
.开发语言:Java、SQL server
.数据库:SQLServer2012
.软件:eclipse
1.2 项目分工
代小龙:管理员的开户,销户,冻结,用户明细,JDBC的连接
安梓玮:存款,转账,查询余额,电话缴费,撰写报告
侯硕:取款,用户界面美化,撰写报告 项目设计方案
实现ATM机的基本功能,包括:查询余额、存款、取款、转账、用户明细、手机缴费以及管理员开户、销户等操作,等基本功能;
查询余额:连接数据库,根据与数据库内数据相同的正确的用户名和密码登录查询对应的余额;转账,存取款的金额必须为100或者是100的整数倍,操作完成后会实时更新数据库内相应的内容。
修改密码:在旧密码相同的情况下,新密码和确认密码也相同的情况下,密码修改完成。
转账:可以转账任何金额,但是当转账金额小于余额时,转账失败。
手机缴费:需要缴费的手机号需时已经存在的,可以存任意金额。
管理员操作的基本功能包括对银行卡开户、销户、冻结、解冻、修改管理员密码等的操作,并在数据库内实时更新。项目功能实现
3.1数据库的实现
card表:主要是用户银行卡的信息,包括账号、密码、余额、是否被冻结、存款余额,其中account是varchar型的主键。
details表:主要是户主名account,日期和资金明细。
GLY表:包含所有管理员的信息。并对管理员的account设为主键。
3.2主要功能实现
3.2.1登录界面package atm_client;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import comm.Card;
import comm.CardGLY;
public class Login extends JFrame {
JTextField tfAccount;
JPasswordField tfPwd;
JButton btOK,btCancel,btGLY;
Card currCard;
CardGLY currCardGLY;
private int count=0;
public void init(){
//界面
JLabel IAccount,IPwd,Itag;
IAccount= new JLabel(”账号:“);
IPwd= new JLabel(”密码:“);
Itag=new JLabel(”欢迎登录ATM系统“);
tfAccount = new JTextField();
tfPwd =new JPasswordField();
btOK=new JButton(”普通登录“);
btGLY=new JButton(”管理员登录“);
btCancel =new JButton(”取消“);
Itag.setFont(new Font(”“,Font.CENTER_BASELINE, 20));
btGLY.setFont(new Font(”“,Font.CENTER_BASELINE, 12));
btOK.setFont(new Font(”“,Font.CENTER_BASELINE, 12));
btCancel.setFont(new Font(”“,Font.CENTER_BASELINE, 12));
IAccount.setFont(new Font(”“,Font.CENTER_BASELINE, 18));
tfAccount.setFont(new Font(”“,Font.CENTER_BASELINE, 18));
tfPwd.setFont(new Font(”“,Font.CENTER_BASELINE, 18));
IPwd.setFont(new Font(”“,Font.CENTER_BASELINE, 18));
JPanel panelOne = new JPanel(null);
panelOne.setOpaque(false);
Itag.setBounds(120,15,350,30);
btOK.setBounds(40, 270, 100, 40);
btGLY.setBounds(160,270,100,40);
btCancel.setBounds(280,270,100,40);
tfAccount.setBounds(160,100,160,40);
IAccount.setBounds(90,105,80,40);
IPwd.setBounds(90, 165,80, 40);
tfPwd.setBounds(160,160,160,40);
panelOne.add(Itag);
panelOne.add(IPwd);
panelOne.add(IAccount);
panelOne.add(btCancel);
panelOne.add(btGLY);
panelOne.add(btOK);
panelOne.add(tfAccount);
panelOne.add(tfPwd);
this.add(panelOne);
this.setTitle(”精神小伙银行“);
this.setBounds(700, 250, 450, 400);
this.setVisible(true);
//监听
//普通用户登录
btOK.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
String account=tfAccount.getText();
String pwd=new String(tfPwd.getPassword());
BufferedReader br=null;
PrintWriter pw=null;
String strEcho=”“;
try {
Socket s=new Socket(InetAddress.getByName(”127.0.0.1“), 8009);
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(s.getOutputStream());
pw.write(”Loginrn“);
pw.write(account+”rn“);
pw.write(pwd+”rn“);
pw.flush();
strEcho=br.readLine();
if(strEcho.equals(”1“)){
JOptionPane.showMessageDialog(Login.this, ”对不起,您的账号有误!“);
tfAccount.setText(”“);
tfPwd.setText(”“);
}else if(strEcho.equals(”2“)){
float money =Float.parseFloat(br.readLine());
String dongjie=br.readLine();
String name=br.readLine();
currCard=new Card(account,pwd,money,dongjie,name);
JOptionPane.showMessageDialog(Login.this, ”欢迎登录河北金苑银行!“);
Login.this.dispose();
new MainFrame(br,pw,currCard).init();
}else if(strEcho.equals(”3“)){
count++;
if(count==3){
JOptionPane.showMessageDialog(Login.this, ”对不起,密码错误3次,您的卡已被冻结!请联系管理员“);
pw.write(”dongjiern“);
pw.flush();
Login.this.dispose();
}else {
JOptionPane.showMessageDialog(Login.this,”密码错误,请重新输入“);
String c=String.valueOf(count);
pw.write(c+”rn“);
pw.flush();
}
}else if(strEcho.equals(”4“)){
JOptionPane.showMessageDialog(Login.this,”对不起,您的卡已被冻结,请联系管理员“);
Login.this.dispose();
}
} catch(UnknownHostException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
} catch(IOException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
//管理员登录
btGLY.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
String account=tfAccount.getText();
String pwd=new String(tfPwd.getPassword());
BufferedReader br=null;
PrintWriter pw=null;
String strEcho=”“;
try {
Socket s=new Socket(InetAddress.getByName(”127.0.0.1“), 8009);
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(s.getOutputStream());
pw.write(”GLYrn“);
pw.write(account+”rn“);
pw.write(pwd+”rn“);
pw.flush();
strEcho=br.readLine();
if(strEcho.equals(”9“)){
JOptionPane.showMessageDialog(Login.this, ”对不起,您的账号有误!“);
tfAccount.setText(”“);
tfPwd.setText(”“);
}else if(strEcho.equals(”8“)){
JOptionPane.showMessageDialog(Login.this,”您已经以管理员身份登录!“);
Login.this.dispose();
new MainFrameGLY(br,pw,currCardGLY).init();
}else if(strEcho.equals(”7“)){
JOptionPane.showMessageDialog(Login.this,”您的密码错误“);
}
} catch(UnknownHostException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
} catch(IOException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
btCancel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
Login.this.dispose();
}
});
}
public static void main(String[] args){
new Login().init();
}
}
3.2.2普通存款界面package atm_client;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import comm.Card;
import atm_client.Take;
public class Save extends JFrame implements ActionListener{
// 存款界面按钮
JTextField tfmoney;
private JButton bt000,bt001,bt002,bt003,bt004,bt005,bt006,bt007,bt008,bt009;
private JButton bt100,bt200,bt300,bt500,bt1000;
private JButton btOK,btCancel,btRetry;
BufferedReader br;
PrintWriter pw;
Card currCard;
public Save(BufferedReader br,PrintWriter pw,Card currCard){
this.br=br;
this.pw=pw;
this.currCard=currCard;
}
public void init(){
JPanel panelTake = new JPanel(null);
panelTake.setBackground(new Color(119,119,253));
JLabel lblqukuan = new JLabel(”请输入您的存款数:“);
panelTake.add(lblqukuan);
lblqukuan.setBounds(115, 20, 150, 30);
lblqukuan=new JLabel(”提示:只能是100元或100元的整数倍。“);
panelTake.add(lblqukuan);
lblqukuan.setBounds(115, 50, 300, 30);
tfmoney=new JTextField(12);
tfmoney.setEnabled(false);
panelTake.add(tfmoney);
tfmoney.setBounds(115,90,200,30);
bt100=new JButton(”100“);
panelTake.add(bt100);
bt100.addActionListener(this);
bt100.setBounds(45,190,60,30);
bt200=new JButton(”200“);
panelTake.add(bt200);
bt200.addActionListener(this);
bt200.setBounds(115,190,60,30);
bt300=new JButton(”300“);
panelTake.add(bt300);
bt300.addActionListener(this);
bt300.setBounds(185,190,60,30);
bt500=new JButton(”500“);
panelTake.add(bt500);
bt500.addActionListener(this);
bt500.setBounds(255,190,60,30);
bt1000=new JButton(”1000“);
panelTake.add(bt1000);
bt1000.addActionListener(this);
bt1000.setBounds(325,190,65,30);
bt001=new JButton(”1“);
panelTake.add(bt001);
bt001.addActionListener(this);
bt001.setBounds(45,230,60,30);
bt002=new JButton(”2“);
panelTake.add(bt002);
bt002.addActionListener(this);
bt002.setBounds(115,230,60,30);
bt003=new JButton(”3“);
panelTake.add(bt003);
bt003.addActionListener(this);
bt003.setBounds(185,230,60,30);
bt004=new JButton(”4“);
panelTake.add(bt004);
bt004.addActionListener(this);
bt004.setBounds(255,230,60,30);
bt005=new JButton(”5“);
panelTake.add(bt005);
bt005.addActionListener(this);
bt005.setBounds(325,230,65,30);
bt006=new JButton(”6“);
panelTake.add(bt006);
bt006.addActionListener(this);
bt006.setBounds(45,270,60,30);
bt007=new JButton(”7“);
panelTake.add(bt007);
bt007.addActionListener(this);
bt007.setBounds(115,270,60,30);
bt008=new JButton(”8“);
panelTake.add(bt008);
bt008.addActionListener(this);
bt008.setBounds(185,270,60,30);
bt009=new JButton(”9“);
panelTake.add(bt009);
bt009.addActionListener(this);
bt009.setBounds(255,270,60,30);
bt000=new JButton(”0“);
panelTake.add(bt000);
bt000.addActionListener(this);
bt000.setBounds(325,270,65,30);
btOK=new JButton(”确定“);
panelTake.add(btOK);
btOK.addActionListener(this);
btOK.setBounds(70,140,80,30);
btRetry=new JButton(”重输“);
panelTake.add(btRetry);
btRetry.addActionListener(this);
btRetry.setBounds(175,140,80,30);
btCancel=new JButton(”返回“);
panelTake.add(btCancel);
btCancel.addActionListener(this);
btCancel.setBounds(280,140,80,30);
this.setTitle(”存款!“);
this.add(panelTake);
this.setSize(435,350);
this.setVisible(true);
this.setLocation(500, 250);
}
@Override
public void actionPerformed(ActionEvent arg0){
// TODO Auto-generated method stub
if(arg0.getSource()==bt100||arg0.getSource()==bt200||arg0.getSource()==bt300||arg0.getSource()==bt500||arg0.getSource()==bt1000)
tfmoney.setText(arg0.getActionCommand());
else if(arg0.getSource()==bt000||arg0.getSource()==bt001||arg0.getSource()==bt002||arg0.getSource()==bt003||arg0.getSource()==bt004||arg0.getSource()==bt005||arg0.getSource()==bt006||arg0.getSource()==bt007||arg0.getSource()==bt008||arg0.getSource()==bt009){
tfmoney.setText(tfmoney.getText()+arg0.getActionCommand());
}else if(arg0.getSource()==btOK){
int saveMoney=Integer.parseInt(tfmoney.getText());
if(saveMoney%100!=0){
JOptionPane.showMessageDialog(Save.this, ”对不起,您输入的金额不符合规定!“);
tfmoney.setText(”“);
}
else{
//发送新的账户信息给服务器
pw.write(”savern“);
pw.write(saveMoney+”rn“);
pw.flush();
//等待响应,更新当前登录账号
String strEcho=”“;
try {
strEcho = br.readLine();
if(strEcho.equals(”Success“)){
currCard.setMoney(currCard.getMoney()+saveMoney);
JOptionPane.showMessageDialog(null, ”恭喜你成功存款“+saveMoney+”元n当前账户余额为:“+currCard.getMoney());
tfmoney.setText(”“);
} else if(strEcho.equals(”Failure“)){
JOptionPane.showMessageDialog(Save.this,”存款失败“);
}
} catch(IOException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else if(arg0.getSource()==btCancel){
Save.this.dispose();
new MainFrame(br,pw,currCard).init();
}else if(arg0.getSource()==btRetry){
tfmoney.setText(”“);
}
}
}
3.2.3用户转账界面package atm_client;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import comm.Card;
public class Trans extends JFrame {
JTextField Taccount,Tmoney;
JButton btOk,btCancel;
JLabel lAccount,lMoney;
BufferedReader br;
PrintWriter pw;
Card currCard;
public Trans(BufferedReader br,PrintWriter pw,Card currCard){
this.br=br;
this.pw=pw;
this.currCard=currCard;
}
public void init(){
JPanel panelTrans=new JPanel(null);
panelTrans.setLayout(new GridLayout(3,2));
lAccount =new JLabel(”账户:“);
lMoney =new JLabel(”金额:“);
btOk = new JButton(”确定“);
btCancel = new JButton(”取消“);
Taccount=new JTextField();
Tmoney = new JTextField();
panelTrans.add(lAccount);
panelTrans.add(Taccount);
panelTrans.add(lMoney);
panelTrans.add(Tmoney);
panelTrans.add(btOk);
panelTrans.add(btCancel);
this.add(panelTrans);
this.setTitle(”转账!“);
this.setSize(300,160);
this.setLocation(500, 250);
this.setVisible(true);
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btOk.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
if(Taccount.getText().equals(”“)){
JOptionPane.showMessageDialog(Trans.this, ”请输入账号“);
}else if(Tmoney.getText().equals(”“)){
JOptionPane.showMessageDialog(Trans.this, ”请输入金额“);
}else {
pw.write(”transrn“);
pw.write(Taccount.getText()+”rn“);
pw.write(Tmoney.getText()+”rn“);
pw.flush();
String strEcho=”“;
try {
strEcho=br.readLine();
if(strEcho.equals(”Success“)){
currCard.setMoney(currCard.getMoney()-Float.parseFloat(Tmoney.getText()));
JOptionPane.showMessageDialog(Trans.this, ”转账成功“);
}else if(strEcho.equals(”1“)){
JOptionPane.showMessageDialog(Trans.this, ”账号不存在“);
}else if(strEcho.equals(”2“)){
JOptionPane.showMessageDialog(Trans.this,”不能向自己转账“);
}else if(strEcho.equals(”3“)){
JOptionPane.showMessageDialog(Trans.this,”余额不足“);
}else if(strEcho.equals(”Fuilure“)){
JOptionPane.showMessageDialog(Trans.this,”转账失败“);
}
} catch(IOException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
btCancel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
Trans.this.dispose();
}
});
}
}
3.2.4手机缴费package atm_client;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import comm.Card;
public class Communi extends JFrame{
JTextField TNumber,Tmoney;
JButton btOk,btCancel;
JLabel INumber,lMoney;
BufferedReader br;
PrintWriter pw;
Card currCard;
public Communi(BufferedReader br,PrintWriter pw,Card currCard){
this.br=br;
this.pw=pw;
this.currCard=currCard;
}
public void init(){
JPanel panelTrans=new JPanel(null);
panelTrans.setLayout(new GridLayout(3,2));
INumber =new JLabel(”账户:“);
lMoney =new JLabel(”金额:“);
btOk = new JButton(”确定“);
btCancel = new JButton(”取消“);
TNumber=new JTextField();
Tmoney = new JTextField();
panelTrans.add(INumber);
panelTrans.add(TNumber);
panelTrans.add(lMoney);
panelTrans.add(Tmoney);
panelTrans.add(btOk);
panelTrans.add(btCancel);
this.add(panelTrans);
this.setTitle(”手机缴费!“);
this.setSize(300,160);
this.setLocation(500, 250);
this.setVisible(true);
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btOk.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
if(TNumber.getText().equals(”“)){
JOptionPane.showMessageDialog(Communi.this, ”请输入手机号“);//导入类——消息对话框
}else if(Tmoney.getText().equals(”“)){
JOptionPane.showMessageDialog(Communi.this, ”请输入金额“);
}else {
pw.write(”communirn“);
pw.write(TNumber.getText()+”rn“);
pw.write(Tmoney.getText()+”rn“);
pw.flush();
String strEcho=”“;
try {
strEcho=br.readLine();
if(strEcho.equals(”Success“)){
currCard.setMoney(currCard.getMoney()-Float.parseFloat(Tmoney.getText()));
JOptionPane.showMessageDialog(Communi.this, ”充值成功“);
Communi.this.dispose();
}else if(strEcho.equals(”1“)){
JOptionPane.showMessageDialog(Communi.this, ”手机号不存在“);
}else if(strEcho.equals(”2“)){
JOptionPane.showMessageDialog(Communi.this,”余额不足“);
}else if(strEcho.equals(”Fuilure“)){
JOptionPane.showMessageDialog(Communi.this,”充值失败“);
}
} catch(IOException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
btCancel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
Communi.this.dispose();
}
});
}
}
3.2.5用户取款package atm_client;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import comm.Card;
import atm_client.Take;
public class Take extends JFrame implements ActionListener{
// 取款界面按钮
JTextField tfmoney;
private JButton bt000,bt001,bt002,bt003,bt004,bt005,bt006,bt007,bt008,bt009;
private JButton bt100,bt200,bt300,bt500,bt1000;
private JButton btOK,btCancel,btRetry;
BufferedReader br;
PrintWriter pw;
Card currCard;
public Take(BufferedReader br,PrintWriter pw,Card currCard){
this.br=br;
this.pw=pw;
this.currCard=currCard;
}
public void init(){
JPanel panelTake = new JPanel(null);
panelTake.setBackground(new Color(119,119,253));
JLabel lblqukuan = new JLabel(”请输入您要取的钱数:“);
panelTake.add(lblqukuan);
lblqukuan.setBounds(115, 20, 150, 30);
lblqukuan=new JLabel(”提示:只能是100元或100元的整数倍。“);
panelTake.add(lblqukuan);
lblqukuan.setBounds(115, 50, 300, 30);
tfmoney=new JTextField(12);
tfmoney.setEnabled(false);
panelTake.add(tfmoney);
tfmoney.setBounds(115,90,200,30);
bt100=new JButton(”100“);
panelTake.add(bt100);
bt100.addActionListener(this);
bt100.setBounds(45,190,60,30);
bt200=new JButton(”200“);
panelTake.add(bt200);
bt200.addActionListener(this);
bt200.setBounds(115,190,60,30);
bt300=new JButton(”300“);
panelTake.add(bt300);
bt300.addActionListener(this);
bt300.setBounds(185,190,60,30);
bt500=new JButton(”500“);
panelTake.add(bt500);
bt500.addActionListener(this);
bt500.setBounds(255,190,60,30);
bt1000=new JButton(”1000“);
panelTake.add(bt1000);
bt1000.addActionListener(this);
bt1000.setBounds(325,190,65,30);
bt001=new JButton(”1“);
panelTake.add(bt001);
bt001.addActionListener(this);
bt001.setBounds(45,230,60,30);
bt002=new JButton(”2“);
panelTake.add(bt002);
bt002.addActionListener(this);
bt002.setBounds(115,230,60,30);
bt003=new JButton(”3“);
panelTake.add(bt003);
bt003.addActionListener(this);
bt003.setBounds(185,230,60,30);
bt004=new JButton(”4“);
panelTake.add(bt004);
bt004.addActionListener(this);
bt004.setBounds(255,230,60,30);
bt005=new JButton(”5“);
panelTake.add(bt005);
bt005.addActionListener(this);
bt005.setBounds(325,230,65,30);
bt006=new JButton(”6“);
panelTake.add(bt006);
bt006.addActionListener(this);
bt006.setBounds(45,270,60,30);
bt007=new JButton(”7“);
panelTake.add(bt007);
bt007.addActionListener(this);
bt007.setBounds(115,270,60,30);
bt008=new JButton(”8“);
panelTake.add(bt008);
bt008.addActionListener(this);
bt008.setBounds(185,270,60,30);
bt009=new JButton(”9“);
panelTake.add(bt009);
bt009.addActionListener(this);
bt009.setBounds(255,270,60,30);
bt000=new JButton(”0“);
panelTake.add(bt000);
bt000.addActionListener(this);
bt000.setBounds(325,270,65,30);
btOK=new JButton(”确定“);
panelTake.add(btOK);
btOK.addActionListener(this);
btOK.setBounds(70,140,80,30);
btRetry=new JButton(”重输“);
panelTake.add(btRetry);
btRetry.addActionListener(this);
btRetry.setBounds(175,140,80,30);
btCancel=new JButton(”返回“);
panelTake.add(btCancel);
btCancel.addActionListener(this);
btCancel.setBounds(280,140,80,30);
this.setTitle(”取款!“);
this.add(panelTake);
this.setSize(435,350);
this.setVisible(true);
this.setLocation(500, 250);
}
@Override
public void actionPerformed(ActionEvent arg0){
// TODO Auto-generated method stub
if(arg0.getSource()==bt100||arg0.getSource()==bt200||arg0.getSource()==bt300||arg0.getSource()==bt500||arg0.getSource()==bt1000)
tfmoney.setText(arg0.getActionCommand());
else if(arg0.getSource()==bt000||arg0.getSource()==bt001||arg0.getSource()==bt002||arg0.getSource()==bt003||arg0.getSource()==bt004||arg0.getSource()==bt005||arg0.getSource()==bt006||arg0.getSource()==bt007||arg0.getSource()==bt008||arg0.getSource()==bt009){
tfmoney.setText(tfmoney.getText()+arg0.getActionCommand());
}else if(arg0.getSource()==btOK){
int takeMoney=Integer.parseInt(tfmoney.getText());
if(currCard.getMoney() JOptionPane.showMessageDialog(Take.this, ”对不起,您的余额不足!“); tfmoney.setText(”“); }else if(takeMoney%100!=0){ JOptionPane.showMessageDialog(Take.this, ”对不起,您输入的金额不符合规定!“); tfmoney.setText(”“); } else{ //发送新的账户信息给服务器 pw.write(”takern“); pw.write(takeMoney+”rn“); pw.flush(); //等待响应,更新当前登录账号 String strEcho=”“; try { strEcho = br.readLine(); if(strEcho.equals(”Success“)){ currCard.setMoney(currCard.getMoney()-takeMoney); JOptionPane.showMessageDialog(null, ”恭喜你成功取款“+takeMoney+”元n当前账户余额为:“+currCard.getMoney()); tfmoney.setText(”“); } else if(strEcho.equals(”Failure“)){ JOptionPane.showMessageDialog(Take.this,”取款失败“); } } catch(IOException e){ // TODO Auto-generated catch block e.printStackTrace(); } } }else if(arg0.getSource()==btCancel){ Take.this.dispose(); }else if(arg0.getSource()==btRetry){ tfmoney.setText(”“); } } } } 3.2.6冻结 package atm_client; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import comm.CardGLY; public class DongJie extends JFrame implements ActionListener{ JButton btOK,btCancel; JTextField Account,Name; BufferedReader br; PrintWriter pw; CardGLY currCardGLY; public DongJie(BufferedReader br,PrintWriter pw,CardGLY currCardGLY){ this.br=br; this.pw=pw; this.currCardGLY=currCardGLY; } public void init(){ JLabel IAccount,IName,Itag; IAccount =new JLabel(”账号“); IName=new JLabel(”用户名“); Itag=new JLabel(”请输入要冻结的账号及用户名“); Account =new JTextField(); Name =new JTextField(); btOK=new JButton(”确定“); btCancel=new JButton(”取消“); Itag.setFont(new Font(”“,Font.CENTER_BASELINE, 20)); btOK.setFont(new Font(”“,Font.CENTER_BASELINE, 12)); btCancel.setFont(new Font(”“,Font.CENTER_BASELINE, 12)); IAccount.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); Account.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); Name.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); IName.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); JPanel panelOne = new JPanel(null); panelOne.setOpaque(false); Itag.setBounds(80,15,350,30); btOK.setBounds(80, 270, 100, 40); btCancel.setBounds(240,270,100,40); Account.setBounds(160,100,160,40); IAccount.setBounds(90,105,80,40); IName.setBounds(90, 165,80, 40); Name.setBounds(160,160,160,40); btCancel.addActionListener(this); btOK.addActionListener(this); panelOne.add(Itag); panelOne.add(IName); panelOne.add(IAccount); panelOne.add(btCancel); panelOne.add(btOK); panelOne.add(Account); panelOne.add(Name); this.add(panelOne); this.setTitle(”代小龙+安梓玮+侯硕“); this.setBounds(700, 250, 450, 400); this.setVisible(true); } @Override public void actionPerformed(ActionEvent arg0){ // TODO Auto-generated method stub if(arg0.getSource()==btOK){ if(Account.getText().equals(”“)||Name.getText().equals(”“)){ JOptionPane.showMessageDialog(DongJie.this,”用户名和账号不能为空“); }else { pw.write(”dongjiern“); pw.write(Account.getText()+”rn“); pw.write(Name.getText()+”rn“); pw.flush(); System.out.println(Name.getText()+Name.getText()); try { String strEcho=br.readLine(); if(strEcho.equals(”9“)){ JOptionPane.showMessageDialog(DongJie.this, ”账号不存在,请重新输入“); Account.setText(”“); Name.setText(”“); }else if(strEcho.equals(”7“)){ JOptionPane.showMessageDialog(DongJie.this, ”冻结成功“); DongJie.this.dispose(); new Ask(br, pw, currCardGLY).init(); }else if(strEcho.equals(”5“)){ JOptionPane.showMessageDialog(DongJie.this, ”用户名错误“); Name.setText(”“); }else if(strEcho.equals(”6“)){ JOptionPane.showMessageDialog(DongJie.this, ”您的账号已被冻结“); DongJie.this.dispose(); }else if(strEcho.equals(”8“)){ JOptionPane.showMessageDialog(DongJie.this, ”冻结失败“); } } catch(IOException e){ // TODO Auto-generated catch block e.printStackTrace(); } } }else if(arg0.getSource()==btCancel){ DongJie.this.dispose(); } } } package atm_client; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import comm.CardGLY; public class Open extends JFrame implements ActionListener{ JTextField tfname;//文本框 JTextField tfmoney; JPasswordField tfpwd;//密码框 JPasswordField tfpwd1; JButton btOK,btCancel; CardGLY currCardGLY; BufferedReader br; PrintWriter pw; public Open(BufferedReader br,PrintWriter pw,CardGLY currCardGLY){ this.br=br; this.pw=pw;//文本字节流写入 this.currCardGLY=currCardGLY; } //初始化 public void init(){ JLabel Iname;//标签组件 JLabel Imoney; JLabel Ipwd,Ipwd1; JLabel Itag=new JLabel(”请输入要开户用户的基本信息“); Ipwd=new JLabel(”密码:“); Ipwd1=new JLabel(”确认密码“); Iname=new JLabel(”姓名:“); Imoney=new JLabel(”预存金额“); tfname=new JTextField(); tfmoney=new JTextField(); btOK=new JButton(”确定“); btCancel=new JButton(”取消“); tfpwd=new JPasswordField(); tfpwd1=new JPasswordField(); Itag.setFont(new Font(”“,Font.CENTER_BASELINE, 20)); Iname.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); tfmoney.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); tfname.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); tfpwd.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); tfpwd1.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); Ipwd.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); Ipwd1.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); Imoney.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); btOK.setFont(new Font(”“,Font.CENTER_BASELINE, 12)); btCancel.setFont(new Font(”“,Font.CENTER_BASELINE, 12)); JPanel panelOne = new JPanel(null); panelOne.setOpaque(false);//设置控件透明 Itag.setBounds(80,15,350,30); Iname.setBounds(70,85,80,40); tfname.setBounds(200,80,160,40); Ipwd.setBounds(70, 135, 80, 40); tfpwd.setBounds(200, 130, 160, 40); Ipwd1.setBounds(70, 185,80, 40); tfpwd1.setBounds(200, 180, 160, 40); Imoney.setBounds(70, 235, 80, 40); tfmoney.setBounds(200, 230, 160, 40); btOK.setBounds(80, 280, 100, 40); btCancel.setBounds(240,280,100,40); btOK.addActionListener(this); btCancel.addActionListener(this); panelOne.add(Itag); panelOne.add(Iname); panelOne.add(Ipwd); panelOne.add(Ipwd1); panelOne.add(Imoney); panelOne.add(tfname); panelOne.add(tfpwd); panelOne.add(tfpwd1); panelOne.add(tfmoney); panelOne.add(btCancel); panelOne.add(btOK); this.add(panelOne); this.setTitle(”代小龙+安梓玮+侯硕“); this.setBounds(700, 250, 450, 400); this.setVisible(true); } //监听button.@Override //socket编程,client发出消息,在Server中接收,并且在接收时采用readline()方法时需要注意,//readline()方法要读到分隔符才会完成读取操作,用pw.write,或者pw.println public void actionPerformed(ActionEvent arg0){ // TODO Auto-generated method stub if(arg0.getSource()==btOK){ //如果事件源始按钮OK,则进行下面操作 if(tfname.getText().equals(”“)||tfpwd.getText().equals(”“)||tfpwd.getText().equals(”“)){ JOptionPane.showMessageDialog(Open.this,”账号密码不能为空“);//导入类——消息对话框 }else if(!tfpwd.getText().equals(tfpwd1.getText())){ JOptionPane.showMessageDialog(Open.this,”两次输入的密码不相同“); tfpwd.setText(”“); tfpwd1.setText(”“); }else if(tfmoney.getText().equals(”“)){ JOptionPane.showMessageDialog(Open.this,”若不需要存钱,请输入0“); }else if(tfpwd.getText().equals(tfpwd1.getText())&&!tfname.getText().equals(”“)&&!tfmoney.getText().equals(”“)){ pw.write(”openrn“);//在服务器获取输入流写入一段字符 pw.write(tfname.getText()+”rn“); pw.write(tfpwd.getText()+”rn“); pw.write(tfmoney.getText()+”rn“); pw.flush(); try { String strEcho=br.readLine(); if(strEcho.equals(”1“)){ JOptionPane.showMessageDialog(Open.this,”开户失败!有用户名重复的可能!“); }else if(strEcho.equals(”2“)){ String account=br.readLine(); JOptionPane.showMessageDialog(Open.this,”开户成功!您的账号为“+account+”,请牢记您的账号“); Open.this.dispose(); } } catch(IOException e){ // TODO Auto-generated catch block e.printStackTrace(); } } }else if(arg0.getSource()==btCancel){ Open.this.dispose(); } } } package atm_client; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import comm.CardGLY; public class Close extends JFrame implements ActionListener { BufferedReader br; PrintWriter pw; CardGLY currCardGLY; private JButton btOK,btCancel; private JTextField tfAccount; private JPasswordField tfPwd; public Close(BufferedReader br,PrintWriter pw,CardGLY currCardGLY){ this.br=br; this.pw=pw; this.currCardGLY=currCardGLY; } public void init(){ JLabel IAccount,IPwd,Itag; IAccount= new JLabel(”账号:“); IPwd= new JLabel(”密码:“); Itag=new JLabel(”请输入要销户的账号及密码“); tfAccount=new JTextField(); tfPwd=new JPasswordField(); btOK=new JButton(”确定“); btCancel=new JButton(”取消“); Itag.setFont(new Font(”“,Font.CENTER_BASELINE, 20)); btOK.setFont(new Font(”“,Font.CENTER_BASELINE, 12)); btCancel.setFont(new Font(”“,Font.CENTER_BASELINE, 12)); IAccount.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); tfAccount.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); tfPwd.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); IPwd.setFont(new Font(”“,Font.CENTER_BASELINE, 18)); JPanel panelOne = new JPanel(null); panelOne.setOpaque(false); Itag.setBounds(120,15,350,30); btOK.setBounds(80, 270, 100, 40); btCancel.setBounds(240,270,100,40); tfAccount.setBounds(160,100,160,40); IAccount.setBounds(90,105,80,40); IPwd.setBounds(90, 165,80, 40); tfPwd.setBounds(160,160,160,40); btCancel.addActionListener(this); btOK.addActionListener(this); panelOne.add(Itag); panelOne.add(IPwd); panelOne.add(IAccount); panelOne.add(btCancel); panelOne.add(btOK); panelOne.add(tfAccount); panelOne.add(tfPwd); this.add(panelOne); this.setTitle(”代小龙+安梓玮+侯硕“); this.setBounds(700, 250, 450, 400); this.setVisible(true); } @Override public void actionPerformed(ActionEvent arg0){ // TODO Auto-generated method stub if(arg0.getSource()==btOK){ String account=tfAccount.getText(); String pwd=new String(tfPwd.getPassword()); pw.write(”closern“); pw.write(account+”rn“); pw.write(pwd+”rn“); pw.flush(); String strEcho; try { strEcho=br.readLine(); if(strEcho.equals(”7“)){ JOptionPane.showMessageDialog(Close.this, ”销户成功“); }else if(strEcho.equals(”9“)){ JOptionPane.showMessageDialog(Close.this, ”您输入的账号不存在“); tfAccount.setText(”“); tfPwd.setText(”“); }else if(strEcho.equals(”8“)){ JOptionPane.showMessageDialog(Close.this, ”销户失败“); }else if(strEcho.equals(”6“)){ JOptionPane.showMessageDialog(Close.this, ”您的密码错误“); tfPwd.setText(”"); } } catch(IOException e){ // TODO Auto-generated catch block e.printStackTrace(); } }else if(arg0.getSource()==btCancel){ Close.this.dispose(); } } }项目总结及展望 本次课程设计主要做的是模拟ATM机,在实现传统的ATM机基础功能的情况下,我们还增添新的内容,用户明细以及话费缴费。实现了普通用户与管理员登录。管理员对用户账号的冻结,解冻。连接数据库并实时更新。将普通用户和管理员的信息分别放在两个表中。 在实现过程中,由于考虑和实现不充分,表的结构过于简单。在实现话费充值上号码预存实现的不人性化,我们后续会加以完善。在接下来的学习中,我们想更加完善ATM功能,并增加新的特色,完善界面。心得体会 通过这次的c/s程序设计,从了解用户需求,到设计数据库,编写代码,连接数据库,调试程序,实现功能我们都得到了很大的进步,我们遇到过很多Bug,我们请教别人,上网查询,最终可以说是得到解决,把老师在课上所授的知识应用到实践中去。c/s程序设计中,是java与连接数据库的统一。为了防止开户生成的账号重复,我们在数据库中对相应的表设置主键,以免重复,在明细中,我们修复了很多问题,克服了很多困难,最终得以实现,感谢申晨老师的帮助,让我们更加深入了解Java语言设计并应用到实践中去。感受到了Java语言编程的魅力,在接下来的时间中,我们不会停止对Java网络项目编程的探索和学习。 参 考 文 献 [1] Eric.Java编程思想[M].第4版.机械工业出版社, 机械工业出版社 [2] JAVA从入门到精通[M].北京:清华大学出版社, 2005.4 [3]萨师煊,王珊.《数据库系统概论》.高等教育出版社,2002.2 [4] Brown.JAVA编程指南(第二版)[M].电子工业出版社,2003.3 [5] 清宏计算机工作室.JAVA编程技巧[M].机械工业出版社,2004.5 [6] 耿祥义,张跃平.JAVA实用教程[M].清华大学出版社,2003.5.1