package customerFinance;
import java.awt.Color;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date; //import java.util.regex.Matcher;
//import java.util.regex.Pattern;
import javax.swing.*;
import DataMethod.DataBase;
import DataMethod.Regex;
;
/**
*
* @author Bondy Zhou
*
*/
public class Transfer extends JPanel implements ActionListener {
private JLabel[] jlArray = { new JLabel("输入您的卡号"), new JLabel("输入您的密码"),
new JLabel("输入对方的卡号"), new JLabel("再次输入对方卡号"), new JLabel("转账数额"),
new JLabel("转账日期") };
private JLabel[] jlArray2 = { new JLabel("卡号是0-9之间10为的数字"),
new JLabel("密码是0-9之间的6位数字 "), new JLabel("卡号是0-9之间10为的数字"),
new JLabel("卡号是0-9之间10为的数字"), new JLabel("金额是0-9之间的数字") };
private JTextField[] jtfArray = { new JTextField(), new JTextField(),
new JTextField(), new JTextField(), new JTextField() };
private JPasswordField jpf = new JPasswordField();
private JButton[] jbArray = { new JButton("验 证"), new JButton("提 交"),
new JButton("重 置") };
private DataBase db = null;
public Transfer() {
this.initialFrame();
this.addListener();
}
public void initialFrame() {
this.setLayout(null);
for (int i = 0; i < jlArray.length; i++) {
jlArray[i].setBounds(30, 20 + 50 * i, 180, 35);
jlArray[i].setFont(new Font("华文行楷", Font.ITALIC + Font.BOLD, 16));
this.add(jlArray[i]);
}
for (int i = 0; i < jlArray2.length; i++) {
jlArray2[i].setBounds(400, 20 + 50 * i, 200, 35);
jlArray2[i].setForeground(Color.RED);
jlArray2[i].setFont(new Font("华文行楷", Font.BOLD, 16));
this.add(jlArray2[i]);
}
jtfArray[0].setBounds(170, 20, 200, 35);
jtfArray[0].setFont(new Font("宋体", Font.BOLD, 16));
this.add(jtfArray[0]);
jpf.setBounds(170, 70, 200, 35);
jpf.setFont(new Font("宋体", Font.BOLD, 16));
this.add(jpf);
for (int i = 1; i < jtfArray.length; i++) {
jtfArray[i].setBounds(170, 20 + 50 * (i + 1), 200, 35);
jtfArray[i].setFont(new Font("宋体", Font.BOLD, 16));
this.add(jtfArray[i]);
jtfArray[i].setEditable(false);
jtfArray[i].addActionListener(this);
}
// 构造注册日期
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
jtfArray[4].setText(sdf.format(date));
jtfArray[4].setEditable(false);
for (int i = 0; i < jbArray.length; i++) {
jbArray[i].setBounds(40 + i * 120, 320, 100, 40);
jbArray[i].setFont(new Font("宋体", Font.BOLD, 16));
this.add(jbArray[i]);
jbArray[i].addActionListener(this);
}
jbArray[1].setEnabled(false);
this.setBackground(Color.CYAN); //设置背景为青色
}
public void addListener() {
jtfArray[0].addActionListener(this);
jpf.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
db = new DataBase();
String sql = null;
String message = null;
String yourCard = jtfArray[0].getText().trim();
String pwd = new String(jpf.getPassword()).trim();
String hisCard = jtfArray[1].getText().trim();
String confirmCard = jtfArray[2].getText().trim();
String transferMoney = jtfArray[3].getText().trim();
String transferDate = jtfArray[4].getText().trim();
Regex r = new Regex();
ResultSet rs = null;
// 增强键盘的可用性,自动移动光标
if (e.getSource() == jtfArray[0]) {
jpf.requestFocus(true);
}
if (e.getSource() == jtfArray[1]) {
jtfArray[2].requestFocus(true);
} else if (e.getSource() == jtfArray[2]) {
jtfArray[3].requestFocus(true);
} else if (e.getSource() == jbArray[2]) {
for (int i = 0; i < jtfArray.length; i++) {
if (i == 0) {
jtfArray[i].setEditable(true);
jpf.setEditable(true);
jtfArray[i].requestFocus(true);
jtfArray[i].setText("");
} else if(i == 4) {
return;
} else {
jpf.setText("");
jtfArray[i].setText("");
jtfArray[i].setEditable(false);
}
}
jpf.setText("");
jpf.setEditable(true);
jbArray[0].setEnabled(true);
jbArray[1].setEnabled(false);
}
else if (e.getSource() == jpf || e.getSource() == jbArray[0]) {
if (yourCard.equals("")) {
jtfArray[0].requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "请输入卡号", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (!r.checkCusId(yourCard)) {
jtfArray[0].requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "卡号是0-9的10位数字", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (pwd.equals("")) {
jpf.requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "请输入密码", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (!r.checkCusPwd(pwd)) {
jpf.requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "密码只能是6位0-9的整数", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
// 得到顾客表中你的的余额信息
sql = "select cusLeftMoney from customer where cusCard = '"
+ yourCard + "'and cusPassword = '" + pwd + "'";
rs = db.selectDb(sql);
try {
if (rs.next()) {
String str = rs.getString(1); // 得到customer中的余额
double yourMoney = Double.parseDouble(str.trim());
if (yourMoney < 10.0) {
jtfArray[0].setText("");
jpf.setText("");
jtfArray[0].requestFocus(true);
JOptionPane.showMessageDialog(this, "您的已余额不足,转账失败",
"错误", JOptionPane.ERROR_MESSAGE);
return;
} else {
int i = JOptionPane.showConfirmDialog(this, "你的余额为" + str
+"元\n请输入转账金额","询问",JOptionPane.YES_NO_OPTION);
//判断是否为该用户,然后进行相应的操作
if(i == JOptionPane.YES_OPTION) {
jtfArray[1].requestFocus(true);
jpf.setEditable(false);
for(int j=0; j<jtfArray.length; j++) {
if(j==0 || j==4) {
jtfArray[j].setEditable(false);
} else {
jtfArray[j].setEditable(true);
}
}
jbArray[0].setEnabled(false);
jbArray[1].setEnabled(true);
} else {
jtfArray[0].requestFocus(true);
}
}
} else {
JOptionPane.showMessageDialog(this, "请检查卡号或密码是否正确", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
} catch (NumberFormatException e1) {
e1.printStackTrace();
} catch (HeadlessException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
db.dbClose();
}
}
else if (e.getSource() == jtfArray[3] || e.getSource() == jbArray[1]) {
int i = 0;
int j = 0;
int k = 0;
int a = 0;
int b = 0;
// 判断输入的情况是否符合实际情况
if (hisCard.equals("")) {
jtfArray[1].requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "请输入对方的卡号", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (!r.checkCusId(hisCard)) {
jtfArray[1].requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "卡号是0-9的10位数字", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (confirmCard.equals("")) {
jtfArray[2].requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "确认卡号不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (!r.checkCusId(confirmCard)) {
jtfArray[2].requestFocus(true); // 将光标转到该文本框
JOptionPane.showMessageDialog(this, "卡号是0-9的10位数字", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (!confirmCard.equals(hisCard
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录




















































































































共 97 条
- 1





格式:x-rar 资源大小:280.9KB










格式:zip 资源大小:48.5KB














煞费苦心2011
- 粉丝: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 网络信息安全B作业题和考试复习题.doc
- 互联网背景下如何提高图书编校质量.docx
- tcpip协议与网络管理标准教程.doc
- 大数据背景下高校思想政治教育过程融入路径探究.docx
- 云南基层干部教育培训信息化建设应用研究教育文档.doc
- 团购网站Groupon及中国电子商务发展分析.doc
- 外贸建站-营销型网站建设.doc
- 斩波电路Matlab仿真电力电子技术课程设计.doc
- 互联网+大连海参养殖新模式探究.docx
- python-游戏数据搜索引擎-基于Python开发的游戏信息检索系统-整合多平台游戏数据-提供快速搜索与详细展示功能-支持用户自定义筛选与收藏-适用于游戏爱好者与开发者查询游戏资.zip
- 人工智能双面观.docx
- 基于欧氏距离的K均方聚类算法研究与应用.docx
- 对安徽江苏山东网络电视台的比较分析.docx
- JavaEEJsp图书系统实用技术文档.doc
- 网络信息安全项目教程习题-解答.doc
- 物联网技术在现代种植业中的应用.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论13