⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addmoneywindow.java

📁 swing+jdbc+sqlserver2000的小型网吧系统
💻 JAVA
字号:
package org.itstar.netbar.swing;

import javax.swing.SwingUtilities;
import java.awt.Point;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JTextField;
import java.awt.Rectangle;
import javax.swing.JComboBox;
import javax.swing.JButton;

import org.itstar.netbar.bean.AddMoneyBean;
import org.itstar.netbar.bean.CustomerBean;
import org.itstar.netbar.domain.IAddMoneyDomain;
import org.itstar.netbar.domain.ICustomerDomain;
import org.itstar.netbar.domain.impl.AddMoneyDomainImpl;
import org.itstar.netbar.domain.impl.CustomerDomainImpl;
import org.itstar.netbar.utils.CurrentTime;

import java.awt.Font;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class AddMoneyWindow {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="73,11"

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JComboBox cboCardNum = null;

	private JLabel jLabel3 = null;

	private JTextField txtPreviousBalance = null;

	private JTextField txtAddMoney = null;

	private JTextField txtCurrentBalance = null;

	private JButton jButton = null;

	private JButton jButton1 = null;

	private JLabel jLabel4 = null;

	private JTextField txtName = null;

	/**
	 * This method initializes cboCardNum	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getCboCardNum() {
		if (cboCardNum == null) {
			cboCardNum = new JComboBox();
			cboCardNum.setBounds(new Rectangle(118, 21, 124, 27));
			cboCardNum.addItem("请先选择..");
			cboCardNum.setFont(new Font("Dialog", Font.BOLD, 14));
			cboCardNum.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if(cboCardNum.getSelectedIndex()>0&&!cboCardNum.getSelectedItem().equals("请先选择.."))
					{
						Map map=new HashMap();
						map.put("cusCardNum", cboCardNum.getSelectedItem());
						ICustomerDomain cDomain=new CustomerDomainImpl();
						List list=new ArrayList();
						list=cDomain.query(map);
						Iterator it=list.iterator();
						CustomerBean cBean=new CustomerBean();
						cBean=(CustomerBean)it.next(); //一定只有一个,所以不需要循环
						txtName.setText(cBean.getCusName());
						txtPreviousBalance.setText(cBean.getCusBalance());
						txtAddMoney.setEditable(true);
					}
					else if(cboCardNum.getSelectedItem().equals("请先选择.."))
					{
						txtName.setText("");
						txtPreviousBalance.setText("");
						txtAddMoney.setText("");
						txtAddMoney.setEditable(false);
						txtCurrentBalance.setText("");
					}
				}
			});
		}
		return cboCardNum;
	}

	/**
	 * This method initializes txtPreviousBalance	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtPreviousBalance() {
		if (txtPreviousBalance == null) {
			txtPreviousBalance = new JTextField();
			txtPreviousBalance.setLocation(new Point(120, 109));
			txtPreviousBalance.setFont(new Font("Dialog", Font.PLAIN, 14));
			txtPreviousBalance.setEditable(false);
			txtPreviousBalance.setEnabled(true);
			txtPreviousBalance.setSize(new Dimension(100, 25));
		}
		return txtPreviousBalance;
	}

	/**
	 * This method initializes txtAddMoney	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtAddMoney() {
		if (txtAddMoney == null) {
			txtAddMoney = new JTextField();
			txtAddMoney.setText("");
			txtAddMoney.setLocation(new Point(120, 153));
			txtAddMoney.setFont(new Font("Dialog", Font.PLAIN, 14));
			txtAddMoney.setEnabled(true);
			txtAddMoney.setEditable(false);
			txtAddMoney.setSize(new Dimension(100, 25));
			txtAddMoney.addFocusListener(new java.awt.event.FocusAdapter() {
				public void focusLost(java.awt.event.FocusEvent e) {
					double iPreBalance=Double.parseDouble(txtPreviousBalance.getText());
					try
					{
						double iAddMoney=Double.parseDouble(txtAddMoney.getText());
						if(iAddMoney<=0.0)
							JOptionPane.showMessageDialog(jFrame,"输入金额不能为负数,请重新输入!","信息提示",JOptionPane.OK_OPTION);
						else
						{
							double temp=iPreBalance+iAddMoney;
							txtCurrentBalance.setText(String.valueOf(temp));
						}
					}
					catch(NumberFormatException ne)
					{//可在此调用信息提示框
						if(!txtAddMoney.getText().equals(""))
							JOptionPane.showMessageDialog(jFrame,"输入金额不是纯数字,请重新输入!","信息提示",JOptionPane.OK_OPTION);
						txtAddMoney.setText("");
					}
					
				}
			});
		}
		return txtAddMoney;
	}

	/**
	 * This method initializes txtCurrentBalance	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtCurrentBalance() {
		if (txtCurrentBalance == null) {
			txtCurrentBalance = new JTextField();
			txtCurrentBalance.setLocation(new Point(120, 193));
			txtCurrentBalance.setFont(new Font("Dialog", Font.PLAIN, 14));
			txtCurrentBalance.setEditable(false);
			txtCurrentBalance.setEnabled(true);
			txtCurrentBalance.setSize(new Dimension(100, 25));
		}
		return txtCurrentBalance;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("确 定");
			jButton.setSize(new Dimension(70, 30));
			jButton.setLocation(new Point(38, 243));
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if(!cboCardNum.getSelectedItem().equals("请先选择..")&&!txtAddMoney.getText().equals(""))
					{
						//添加冲值记录
						IAddMoneyDomain amDomain=new AddMoneyDomainImpl();
						AddMoneyBean amBean=new AddMoneyBean();
						amBean.setAddCusCardNum(cboCardNum.getSelectedItem().toString());
						amBean.setAddAmount(txtAddMoney.getText());
						amBean.setAddDate(CurrentTime.getCurTime());
						amDomain.insert(amBean);
						
						//更新会员表中相应记录的余额字段
						ICustomerDomain cDomain=new CustomerDomainImpl();
						CustomerBean cBean=new CustomerBean();
						cBean.setCusCardNum(cboCardNum.getSelectedItem().toString());
						cBean.setCusBalance(txtCurrentBalance.getText());
						cDomain.updateBalance(cBean);
						
						JOptionPane.showMessageDialog(jFrame, "冲值成功!金额为 "+txtAddMoney.getText()+" 元");
						cboCardNum.setSelectedItem("请先选择..");
					}
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("取 消");
			jButton1.setSize(new Dimension(70, 30));
			jButton1.setLocation(new Point(133, 242));
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jFrame.dispose();
				}
			});
		}
		return jButton1;
	}

	/**
	 * This method initializes txtName	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtName() {
		if (txtName == null) {
			txtName = new JTextField();
			txtName.setEditable(false);
			txtName.setSize(new Dimension(100, 25));
			txtName.setFont(new Font("Dialog", Font.PLAIN, 14));
			txtName.setLocation(new Point(119, 66));
		}
		return txtName;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自动生成方法存根
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AddMoneyWindow application = new AddMoneyWindow();
				application.getJFrame().setVisible(true);
			}
		});
	}

	/**
	 * This method initializes jFrame
	 * 
	 * @return javax.swing.JFrame
	 */
	public JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			jFrame.setAlwaysOnTop(true);
			jFrame.setSize(268, 340);
			jFrame.setLocation(new Point(200, 150));
			jFrame.setContentPane(getJContentPane());
			jFrame.setTitle("会员冲值");
			jFrame.addWindowListener(new java.awt.event.WindowAdapter() {
				public void windowOpened(java.awt.event.WindowEvent e) {
					ICustomerDomain amDomain=new CustomerDomainImpl();
					CustomerBean cBean=new CustomerBean();
					List list=new ArrayList();
					list=amDomain.queryAll();
					Iterator it=list.iterator();
					while(it.hasNext())
					{
						cBean=(CustomerBean)it.next();
						cboCardNum.addItem(cBean.getCusCardNum());
					}
				}
			});
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel4 = new JLabel();
			jLabel4.setPreferredSize(new Dimension(60, 20));
			jLabel4.setLocation(new Point(37, 67));
			jLabel4.setSize(new Dimension(70, 24));
			jLabel4.setFont(new Font("Dialog", Font.BOLD, 14));
			jLabel4.setText("会员名称");
			jLabel3 = new JLabel();
			jLabel3.setFont(new Font("Dialog", Font.BOLD, 14));
			jLabel3.setLocation(new Point(37, 193));
			jLabel3.setSize(new Dimension(70, 24));
			jLabel3.setText("当前结余");
			jLabel2 = new JLabel();
			jLabel2.setFont(new Font("Dialog", Font.BOLD, 14));
			jLabel2.setLocation(new Point(37, 154));
			jLabel2.setSize(new Dimension(70, 24));
			jLabel2.setText("冲值金额");
			jLabel1 = new JLabel();
			jLabel1.setFont(new Font("Dialog", Font.BOLD, 14));
			jLabel1.setLocation(new Point(37, 111));
			jLabel1.setSize(new Dimension(70, 24));
			jLabel1.setText("上次结余");
			jLabel = new JLabel();
			jLabel.setFont(new Font("Dialog", Font.BOLD, 14));
			jLabel.setLocation(new Point(37, 23));
			jLabel.setSize(new Dimension(70, 24));
			jLabel.setText("会员卡号");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(getCboCardNum(), null);
			jContentPane.add(jLabel3, null);
			jContentPane.add(getTxtPreviousBalance(), null);
			jContentPane.add(getTxtAddMoney(), null);
			jContentPane.add(getTxtCurrentBalance(), null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJButton1(), null);
			jContentPane.add(jLabel4, null);
			jContentPane.add(getTxtName(), null);
		}
		return jContentPane;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -