📄 newaccout.java
字号:
package cn.hebut;
import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JList;
import java.awt.Choice;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import javax.swing.WindowConstants;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPasswordField;
public class Newaccout extends JDialog {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
private JLabel jLabel6 = null;
private JLabel jLabel7 = null;
private JTextField jnumber = null;
private JTextField jname1 = null;
private JTextField jaddress = null;
private JTextField jrate = null;
private JButton jButton = null;
private JButton jcancel = null;
public static String newaccout[]=new String[8]; // @jve:decl-index=0:
public JComboBox jComboBox = null;
public JComboBox jComboBox1 = null;
private JPasswordField jPassword = null;
private JPasswordField jPassword2 = null;
private JLabel jLabel8 = null;
/**
* @param owner
*/
public Newaccout() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(664, 506);
this.setTitle("开户");
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setVisible(true);
this.setContentPane(getJContentPane());
this.setModal(true); }
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel8 = new JLabel();
jLabel8.setBounds(new Rectangle(343, 21, 114, 18));
jLabel8.setText("填入五位数字卡号");
jLabel7 = new JLabel();
jLabel7.setBounds(new Rectangle(22, 348, 74, 22));
jLabel7.setText("利率:");
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(22, 307, 74, 22));
jLabel6.setText("住址:");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(22, 261, 74, 22));
jLabel5.setText("存款日期:");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(22, 215, 74, 22));
jLabel4.setText("存款类型:");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(22, 167, 74, 22));
jLabel3.setText("确认密码:");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(22, 117, 74, 22));
jLabel2.setText("密码:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(22, 71, 74, 22));
jLabel1.setText("用户名:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(22, 23, 74, 22));
jLabel.setText("账户号:");
jContentPane = new JPanel();
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel, null);
jContentPane.setLayout(null);
jContentPane.add(jLabel2, null);
jContentPane.add(jLabel4, null);
jContentPane.add(jLabel5, null);
jContentPane.add(jLabel3, null);
jContentPane.add(jLabel6, null);
jContentPane.add(getJnumber(), null);
jContentPane.add(getJname1(), null);
jContentPane.add(jLabel7, null);
jContentPane.add(getJaddress(), null);
jContentPane.add(getJrate(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJcancel(), null);
jContentPane.add(getJComboBox(), null);
jContentPane.add(getJComboBox1(), null);
jContentPane.add(getJPassword(), null);
jContentPane.add(getJPassword2(), null);
jContentPane.add(jLabel8, null);
jContentPane.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent e) {
if(jComboBox1.getSelectedItem().equals("活期"))
{ String lx="0.72%";
jrate.setText(lx);
}
if(jComboBox1.getSelectedItem().equals("死期"))
{ String lx="0.95%";
jrate.setText(lx);
}
}
});
}
return jContentPane;
}
public void get()
{
newaccout[0]=jnumber.getText();
newaccout[1]=jname1.getText();
newaccout[2]=jPassword.getText();
newaccout[3]=jPassword2.getText();
newaccout[4]=(String) jComboBox1.getSelectedItem();
newaccout[5]=(String) jComboBox.getSelectedItem();
newaccout[6]=jaddress.getText();
newaccout[7]=jrate.getText();
}
/**
* This method initializes jnumber
*
* @return javax.swing.JTextField
*/
private JTextField getJnumber() {
if (jnumber == null) {
jnumber = new JTextField();
jnumber.setBounds(new Rectangle(160, 21, 145, 22));
}
return jnumber;
}
/**
* This method initializes jname1
*
* @return javax.swing.JTextField
*/
private JTextField getJname1() {
if (jname1 == null) {
jname1 = new JTextField();
jname1.setBounds(new Rectangle(160, 68, 145, 22));
}
return jname1;
}
/**
* This method initializes jaddress
*
* @return javax.swing.JTextField
*/
private JTextField getJaddress() {
if (jaddress == null) {
jaddress = new JTextField();
jaddress.setBounds(new Rectangle(160, 306, 145, 22));
}
return jaddress;
}
/**
* This method initializes jrate
*
* @return javax.swing.JTextField
*/
private JTextField getJrate() {
if (jrate == null) {
jrate = new JTextField();
jrate.setBounds(new Rectangle(160, 346, 145, 22));
jrate.setEditable(false);
}
return jrate;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(79, 415, 111, 22));
jButton.setText("确认");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
get();
if(check())
{
if(yanzheng())
{
JOptionPane.showMessageDialog(null, "开户成功!");
intodata();
}
}
}
});
}
return jButton;
}
/**
* This method initializes jcancel
*
* @return javax.swing.JButton
*/
private JButton getJcancel() {
if (jcancel == null) {
jcancel = new JButton();
jcancel.setBounds(new Rectangle(261, 416, 124, 21));
jcancel.setText("取消");
jcancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Newaccout.this.dispose(); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jcancel;
}
public void intodata()
{
Statement stmt=null;
Connection conn=Sql.link();//连接数据库
try {
stmt=conn.createStatement();
stmt.execute("insert into 储户信息 (账户号,用户姓名,用户密码,住址,存款类型,存款日期,利率)" +
"values('"+newaccout[0]+"','"+newaccout[1]+"','"+newaccout[2]+"','"+newaccout[6]+"','"+newaccout[4]+"','"+newaccout[5]+"','"+newaccout[7]+"')");
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
try {
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public boolean check()
{
if(jnumber.getText().equals("")||jname1.getText().equals("")||jPassword.getText().equals("")||jPassword2.getText().equals("")||jComboBox1.getSelectedItem().equals("")||jaddress.getText().equals(""))
{JOptionPane.showMessageDialog(null, "必添项请填写完全!");
return false;
}
if(!Mainframe.numValid(jnumber.getText()))
{
JOptionPane.showMessageDialog(null, "请输入5位的数字卡号!");
return false;
}
else
{
//if(!Mainframe.moneyValid(s))
if(!jPassword.getText().equals(jPassword2.getText()))//检查用户名和密码
{
JOptionPane.showMessageDialog(null, "两次输入的密码不一样,请重新输入:");
return false;
}
}
return true;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox();
jComboBox.setBounds(new Rectangle(160, 260, 145, 22));
Calendar calCurrent =Calendar.getInstance();
int day=calCurrent.get(Calendar.DATE);
int month=calCurrent.get(Calendar.MONTH)+1;
int year=calCurrent.get(Calendar.YEAR);
String time=year+"-"+month+"-"+day;
jComboBox.addItem(time);
}
return jComboBox;
}
/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox();
jComboBox1.setBounds(new Rectangle(160, 211, 141, 22));
jComboBox1.addItem("活期");
jComboBox1.addItem("死期");
}
return jComboBox1;
}
/**
* This method initializes jPassword
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPassword() {
if (jPassword == null) {
jPassword = new JPasswordField();
jPassword.setBounds(new Rectangle(160, 113, 145, 22));
}
return jPassword;
}
/**
* This method initializes jPassword2
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPassword2() {
if (jPassword2 == null) {
jPassword2 = new JPasswordField();
jPassword2.setBounds(new Rectangle(160, 163, 146, 22));
}
return jPassword2;
}
public boolean yanzheng(){
ResultSet rset=null;
Statement stmt=null;
Connection conn=Sql.link();//连接数据库
try {
stmt=conn.createStatement();
rset=stmt.executeQuery("select * from 储户信息 where 账户号='"+jnumber.getText()+"'");
if(rset.next())//验证用户名是否存在
{
JOptionPane.showMessageDialog(null, "该账号已存在,请重新输入!");
return false;
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
return false;
}
try {
rset.close();
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
return false;
}
return true;
}
} // @jve:decl-index=0:visual-constraint="185,-55"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -