📄 storepanel.java
字号:
package com.vbank.operate;
import com.vbank.db.*;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
public class StorePanel extends JPanel {
private static final long serialVersionUID = 1L;
private static String opnum=null;
private JLabel jLabel = null;
private JTextField jTextField = null;
private JLabel jLabel1 = null;
private JTextField jTextField1 = null;
private JButton jButton = null;
private JPanel jPanel = null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
private JLabel jLabel6 = null;
private JLabel jLabel7 = null;
private JLabel jLabel8 = null;
private JLabel jLabel9 = null;
private JLabel jLabel10 = null;
private JButton jButton1 = null;
private JComboBox jComboBox = null;
private JLabel jLabel2 = null;
private JLabel jLabel11 = null;
private JRadioButton jRadioButton = null;
private JRadioButton jRadioButton1 = null;
private JLabel jLabel12 = null;
private JCheckBox jCheckBox = null;
private JLabel jLabel13 = null;
private JLabel jLabel14 = null;
private JTextField jTextField2 = null;
private JLabel jLabel15 = null;
/**
* This is the default constructor
*/
public StorePanel(String operator) {
super();
opnum=operator;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabel15 = new JLabel();
jLabel15.setBounds(new Rectangle(438, 117, 25, 20));
jLabel15.setText("月");
jLabel14 = new JLabel();
jLabel14.setBounds(new Rectangle(316, 113, 70, 28));
jLabel14.setText("存款期限:");
jLabel13 = new JLabel();
jLabel13.setBounds(new Rectangle(229, 114, 81, 22));
jLabel13.setText("是否自动转存");
jLabel12 = new JLabel();
jLabel12.setBounds(new Rectangle(117, 112, 57, 24));
jLabel12.setText("定期");
jLabel11 = new JLabel();
jLabel11.setBounds(new Rectangle(46, 108, 35, 30));
jLabel11.setText("活期");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(308, 31, 82, 27));
jLabel2.setText("币种:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(13, 74, 69, 26));
jLabel1.setText("金额:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(14, 31, 67, 25));
jLabel.setText("输入帐号:");
this.setSize(549, 385);
this.setLayout(null);
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), "\u5b58\u6b3e\u9762\u677f", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, new Font("\u5b8b\u4f53", Font.PLAIN, 12), Color.green));
this.add(jLabel, null);
this.add(getJTextField(), null);
this.add(jLabel1, null);
this.add(getJTextField1(), null);
this.add(getJButton(), null);
this.add(getJPanel(), null);
this.add(getJComboBox(), null);
this.add(jLabel2, null);
this.add(jLabel11, null);
ButtonGroup group = new ButtonGroup ();
group.add(getJRadioButton());
group.add(getJRadioButton1());
this.add(getJRadioButton(), null);
this.add(getJRadioButton1(), null);
this.add(jLabel12, null);
this.add(getJCheckBox(), null);
this.add(jLabel13, null);
this.add(jLabel14, null);
this.add(getJTextField2(), null);
this.add(jLabel15, null);
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(87, 31, 203, 28));
jTextField.setName("account");
}
return jTextField;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new Rectangle(87, 71, 204, 30));
}
return jTextField1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(205, 152, 89, 30));
jButton.setText("存款");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("store actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
store();
}
});
}
return jButton;
}
private void store() {
String account=jTextField.getText().trim();
String bizhong=(String)jComboBox.getSelectedItem();
String gold=jTextField1.getText().trim();
String storekind="活期";
if(jRadioButton1.isSelected())storekind="定期";
String storeday=jTextField2.getText().trim();
int day=0;
if(storekind=="定期") {
day=new Integer(storeday).intValue();
}
String auto="n";
if(jCheckBox.isSelected())auto="y";
float money=new Float(gold).floatValue();
String select="select * from account where accountNum='"+account+"'";
DBManager.getConnection();
int i=DBManager.executeQuery(select);
if(i!=0) {
JOptionPane.showMessageDialog(this, "您的帐号填错了", "alert", JOptionPane.ERROR_MESSAGE);
return;
}else {
String sql="update account set balance=balance+"+money+" where accountNum='"+account+"'";
System.out.println(sql);
//DBManager.getConnection();
DBManager.execUpdate(sql);
System.out.println(sql);
showAccount(account,gold);
sql="insert into storelog(operateNum,storeMoney,moneyType,storedate,storeKind ,autoStoreToAccount,accountnum)values('"+
opnum+"',"+money+",'"+bizhong+"',"+day+",'"+storekind+"','"+auto+"','"+account+"')";
System.out.println(sql);
// DBManager.getConnection();
int t=DBManager.execInsert(sql);
if(t!=0) {
JOptionPane.showMessageDialog(this, "已经存款到帐号");
showAccount(jTextField.getText().trim(),jTextField1.getText().trim());
jPanel.setVisible(true);
repaint();
}
}//DBManager.releaseCon();
}
private void showAccount(String account,String gold) {
String sql="select balance ,interests from account a"+
" where a.accountNum='"+account+"'";
DBManager.getConnection();
ResultSet rs=DBManager.executeSelect(sql);
try {
if(rs.next()) {
jLabel6.setText(rs.getString("balance"));
jLabel10.setText(rs.getString("interests"));
jLabel4.setText(account);
jLabel8.setText(gold);
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
/*
protected void paintComponent(Graphics g) {
showAccount(jTextField.getText().trim(),jTextField1.getText().trim());
jPanel.setVisible(true);
super.paint(g);
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLabel10 = new JLabel();
jLabel10.setBounds(new Rectangle(145, 138, 184, 30));
jLabel10.setText("JLabel");
jLabel9 = new JLabel();
jLabel9.setBounds(new Rectangle(28, 137, 109, 26));
jLabel9.setText("利息:");
jLabel8 = new JLabel();
jLabel8.setBounds(new Rectangle(146, 104, 184, 27));
jLabel8.setText("JLabel");
jLabel7 = new JLabel();
jLabel7.setBounds(new Rectangle(29, 105, 109, 26));
jLabel7.setText("本次存款额:");
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(147, 73, 183, 28));
jLabel6.setText("JLabel");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(31, 71, 109, 27));
jLabel5.setText("帐户余额:");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(148, 32, 182, 31));
jLabel4.setText("JLabel");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(32, 31, 111, 27));
jLabel3.setText("帐号:");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(4, 185, 477, 196));
jPanel.setBorder(BorderFactory.createTitledBorder(null, "\u8bf7\u786e\u8ba4\u672c\u6b21\u64cd\u4f5c", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, new Font("\u5b8b\u4f53", Font.PLAIN, 12), Color.red));
jPanel.add(jLabel3, null);
jPanel.add(jLabel4, null);
jPanel.add(jLabel5, null);
jPanel.add(jLabel6, null);
jPanel.add(jLabel7, null);
jPanel.add(jLabel8, null);
jPanel.add(jLabel9, null);
jPanel.add(jLabel10, null);
jPanel.add(getJButton1(), null);
jPanel.setVisible(false);
}
return jPanel;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(39, 175, 122, 33));
jButton1.setText("确认");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
clear(); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton1;
}
private void clear() {
jPanel.setVisible(false);
jTextField.setText("");
jTextField1.setText("");
jLabel6.setText("");
jLabel10.setText("");
jLabel4.setText("");
jLabel8.setText("");
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox();
jComboBox.setBounds(new Rectangle(399, 33, 65, 23));
jComboBox.addItem("人民币");
jComboBox.addItem("美元");
}
return jComboBox;
}
/**
* This method initializes jRadioButton
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton() {
if (jRadioButton == null) {
jRadioButton = new JRadioButton();
jRadioButton.setBounds(new Rectangle(26, 111, 23, 22));
jRadioButton.setSelected(true);
//jTextField2.setEditable(true);
}
return jRadioButton;
}
/**
* This method initializes jRadioButton1
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton1() {
if (jRadioButton1 == null) {
jRadioButton1 = new JRadioButton();
jRadioButton1.setBounds(new Rectangle(91, 113, 21, 21));
jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
//System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged()
if(jRadioButton1.isSelected()) {
jCheckBox.setEnabled(true);
jTextField2.setEditable(true);
}else {
jCheckBox.setEnabled(false);
jCheckBox.setSelected(false);
jTextField2.setEditable(false);
}
}
});
}
return jRadioButton1;
}
/**
* This method initializes jCheckBox
*
* @return javax.swing.JCheckBox
*/
private JCheckBox getJCheckBox() {
if (jCheckBox == null) {
jCheckBox = new JCheckBox();
jCheckBox.setBounds(new Rectangle(194, 116, 21, 21));
jCheckBox.setEnabled(false);
}
return jCheckBox;
}
/**
* This method initializes jTextField2
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
jTextField2.setBounds(new Rectangle(389, 113, 46, 26));
jTextField2.setEditable(false);
}
return jTextField2;
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -