📄 applypanel.java
字号:
package bank;
import javax.swing.JPanel;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.Font;
import java.awt.Color;
import com.borland.jbcl.layout.XYConstraints;
import javax.swing.JComboBox;
import com.borland.jbcl.layout.XYLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JToggleButton;
import java.sql.Connection;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.SystemColor;
import java.awt.Dimension;
import javax.swing.JOptionPane;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.sql.PreparedStatement;
public class ApplyPanel extends JPanel {
public ApplyPanel() {
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
private String name;
private String city;
private String bankname;
private String mima;
private long accountID=12345;
private String customer_id;
private Connection con;
private String index="";
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JLabel jLabel3 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JToggleButton jToggleButton1 = new JToggleButton();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField jTextField4 = new JTextField();
TitledBorder titledBorder1 = new TitledBorder("");
TitledBorder titledBorder2 = new TitledBorder("");
JLabel jLabel7 = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JLabel jLabel8 = new JLabel();
JTextField jTextField5 = new JTextField();
JLabel jLabel9 = new JLabel();
private void jbInit() throws Exception {
this.setLayout(xYLayout1);
this.setSize(new Dimension(431, 351));
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel1.setForeground(Color.red);
jLabel1.setToolTipText("");
jLabel1.setText("城市");
jLabel2.setFont(new java.awt.Font("华文细黑", Font.PLAIN, 16));
jLabel2.setForeground(Color.red);
jLabel2.setText("姓名:");
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton1.setBorder(titledBorder2);
jButton1.setText("确定");
jButton1.addActionListener(new ApplyPanel_jButton1_actionAdapter(this));
jLabel3.setFont(new java.awt.Font("华文细黑", Font.PLAIN, 16));
jLabel3.setForeground(Color.red);
jLabel3.setText("请正确填以下信息:");
jToggleButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jToggleButton1.setBorder(titledBorder1);
jToggleButton1.setText("重置");
jToggleButton1.addActionListener(new
ApplyPanel_jToggleButton1_actionAdapter(this));
jLabel4.setFont(new java.awt.Font("华文细黑", Font.PLAIN, 16));
jLabel4.setForeground(Color.red);
jLabel4.setText("密码:");
jLabel5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel5.setForeground(Color.red);
jLabel5.setText("选择卡类型:");
this.setBackground(new Color(176, 227, 110));
jLabel6.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel6.setForeground(Color.red);
jLabel6.setText("客户ID号:");
jComboBox1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jLabel7.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel7.setForeground(Color.red);
jLabel7.setText("职业:");
jComboBox2.addItem("学生");
jComboBox2.addItem("无业人士");
jComboBox2.addItem("农民");
jComboBox2.addItem("老师");
jComboBox2.addItem("上班一族");
jComboBox2.addItem("政府部门人员");
jComboBox2.addItem("个体户");
jComboBox2.addItem("其他");
jLabel8.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel8.setForeground(Color.red);
jLabel8.setText("存款金额:");
jLabel9.setText("(不少于10元)");
this.add(jLabel3, new XYConstraints(10, 18, -1, -1));
this.add(jLabel4, new XYConstraints(44, 96, -1, -1));
this.add(jLabel1, new XYConstraints(44, 137, -1, -1));
this.add(jLabel2, new XYConstraints(44, 55, -1, -1));
this.add(jTextField2, new XYConstraints(133, 92, 145, 32));
this.add(jTextField1, new XYConstraints(133, 56, 145, 30));
this.add(jTextField3, new XYConstraints(132, 133, 144, 34));
this.add(jTextField4, new XYConstraints(134, 179, 144, 31));
this.add(jComboBox1, new XYConstraints(133, 221, 145, 34));
this.add(jLabel6, new XYConstraints(46, 176, 82, 42));
this.add(jLabel5, new XYConstraints(46, 226, -1, -1));
this.add(jComboBox2, new XYConstraints(131, 310, 147, 33));
this.add(jLabel7, new XYConstraints(46, 303, 72, 35));
this.add(jLabel8, new XYConstraints(45, 273, 87, 29));
this.add(jTextField5, new XYConstraints(131, 269, 144, 32));
this.add(jButton1, new XYConstraints(323, 154, 75, 34));
this.add(jLabel9, new XYConstraints(278, 276, 91, 28));
this.add(jToggleButton1, new XYConstraints(323, 215, 72, 36));
try{
con = bankconnect.getconn();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select branch_name from card");
String a;
while(rs.next())//一行行的移
{
a=rs.getString("branch_name");
jComboBox1.addItem(a);
}
rs.close();
con.close();
this.hide();
return;
}
catch(SQLException ex)
{
System.out.print("数据库连接出错!"+ex.toString());
}
}
public void jToggleButton1_actionPerformed(ActionEvent e) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
}
public void jButton1_actionPerformed(ActionEvent e)
{
float money=0;
name=jTextField1.getText();
mima=jTextField2.getText();
city=jTextField3.getText();
money=Float.parseFloat(jTextField5.getText().trim());
bankname=jComboBox1.getSelectedItem().toString().trim();
customer_id=jTextField4.getText().trim();
index=jComboBox2.getSelectedItem().toString().trim();
if(money<10){jTextField5.setText("金额不足");return;}
if(mima.equals("")){jTextField2.setText("请输入密码");return;}
if(name.equals("")){jTextField1.setText("请输入姓名");return;}
if(city.equals("")){jTextField3.setText("请输入所在城市");return;}
if(customer_id.equals("")){jTextField3.setText("请输入证件号码");return;}
int i=0;
try
{
con = bankconnect.getconn();
Statement stmt = con.createStatement();
if(index.equals("学生")) i=2;
else if(index.equals("无业人士")) i=3;
else if(index.equals("农民")) i=5;
else if(index.equals("上班一族")) i=10;
else if(index.equals("政府部门人员")) i=20;
else if(index.equals("个体户")) i=30;
else i=1;
//事务!!!!!////////////////////////
try{
con.setAutoCommit(false);
PreparedStatement pst = null;
String sql = "select * from account";
String a = "";
long j=1;
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
// a=rs.getString("account_num");
j=rs.getLong("account_num");
if(accountID<j) accountID=j;
}
accountID =accountID+1;
stmt.executeUpdate("insert customer(customer_id,customer_name,customer_city,customer_lever) values('" +
customer_id + "','" + name + "','" + city + "',1 )");
sql="insert into account(account_num,branch_name,balance,account_pswd,last_time) values('"+accountID+"','"+bankname+"',10,'"+mima+"','"+TodayTime.getLongDate()+"')";//insert account
stmt.executeUpdate(sql);
sql="insert into depositor(customer_id,account_num) values('"+customer_id+"','"+accountID+"')";//insert depositor
stmt.executeUpdate(sql);
con.commit();
con.setAutoCommit(true);
con.close();
String me="卡号是:"+accountID+",请记住!!!!";
JOptionPane.showMessageDialog(null,me);
}
catch(Exception exp){
con.rollback();
con.close();
exp.printStackTrace();
}
}
catch(SQLException ex)
{
System.out.println("数据库连接错误!"+ex.toString());
}
}
}
class ApplyPanel_jButton1_actionAdapter
implements ActionListener {
private ApplyPanel adaptee;
ApplyPanel_jButton1_actionAdapter(ApplyPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class ApplyPanel_jToggleButton1_actionAdapter
implements ActionListener {
private ApplyPanel adaptee;
ApplyPanel_jToggleButton1_actionAdapter(ApplyPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jToggleButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -