?? addmoneywindow.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(); //一定只有一個,所以不需要循環(huán)
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,"輸入金額不能為負數(shù),請重新輸入!","信息提示",JOptionPane.OK_OPTION);
else
{
double temp=iPreBalance+iAddMoney;
txtCurrentBalance.setText(String.valueOf(temp));
}
}
catch(NumberFormatException ne)
{//可在此調(diào)用信息提示框
if(!txtAddMoney.getText().equals(""))
JOptionPane.showMessageDialog(jFrame,"輸入金額不是純數(shù)字,請重新輸入!","信息提示",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);
//更新會員表中相應(yīng)記錄的余額字段
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("當前結(jié)余");
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("上次結(jié)余");
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 + -