📄 viprechargepanel.java
字号:
/**
*
*/
package view.panel.vip;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import view.common.CheckInputUtil;
import view.common.GBC;
import view.frame.MainFrame;
import vo.VipChargeVo;
import control.vip.VipRechargePanelListener;
/**
* @author lulicheng
* @version 1.0
*
*/
public class VipRechargePanel extends JPanel {
// =====该面板的三个分块面板=====
JPanel infoPanel, rechargePanel, actionPanel;
// -----构建consumerInfoPanel的组件-----
// 该面板的标签-姓名标签,编号标签,电话号码标签,余额标签
JLabel nameLabel, idLabel, phoneLabel, balanceLabel;
// 文本域-姓名文本, 编号文本,电话文本,余额文本
JTextField nameField, idField, phoneField, balanceField;
// -----构建rechargeInputPanel的组件-----
// 收受现金数额标签,实际充值数额标签
JLabel recieveLabel, rechargeLabel;
// 收受现金数额文本域,实际充值数额文本域
JTextField recieveFeild, rechargeFeild;
// -----构建actionPanel的组件-----
// 勾选现金充值标签,勾选打印小单标签
JLabel cashCheckLabel, printCheckLabel;
// 现金充值勾选框,打印小单勾选框
JCheckBox cashCheck, printCheck;
// 按钮确定(F5),按钮取消(F4)
JButton buttonOk, buttonCancel;
/*
* 需要与其他面板进行数据交互所定义的属性
*/
// 会员管理面板
VipManagePanel managePanel = null;
/**
* 构造函数,设定该面板的布局以及添加的组件
*/
public VipRechargePanel(JDialog dialog) {
this.setSize(420, 260);
this.setLayout(new BorderLayout());
initComponent();
this.add(buildInfoPanel(), BorderLayout.NORTH);
this.add(buildRechargePanel(), BorderLayout.CENTER);
this.add(buildActionPanel(dialog), BorderLayout.SOUTH);
this.recieveFeild.requestFocus();
}
/**
* 构造函数,设定该面板的布局以及添加的组件
*/
public VipRechargePanel(VipManagePanel managePanel, JDialog dialog) {
this.managePanel = managePanel;
this.setSize(420, 260);
this.setLayout(new BorderLayout());
initComponent();
this.add(buildInfoPanel(), BorderLayout.NORTH);
this.add(buildRechargePanel(), BorderLayout.CENTER);
this.add(buildActionPanel(dialog), BorderLayout.SOUTH);
}
/**
* 初始化组件,包括初始化该面板的标签,文本域这两类不需要添加时间的控件
*/
public void initComponent() {
initJLabel();
initJTextFeild();
if(managePanel/*.getSelectedData() */== null){
System.out.println("managePanel.getSelectedData() == null");
}else{
initialVipInfoTableValue(managePanel.getSelectedData());
}
}
public void initialVipInfoTableValue(String[] value) {
idField.setText(value[0]);
nameField.setText(value[1]);
phoneField.setText(value[7]);
balanceField.setText(value[5]);
idField.setEditable(false);
nameField.setEditable(false);
phoneField.setEditable(false);
balanceField.setEditable(false);
}
/*
* 初始化文本标签
*/
public void initJLabel() {
nameLabel = new JLabel("会员姓名");
idLabel = new JLabel("会员编号");
phoneLabel = new JLabel("会员电话");
balanceLabel = new JLabel("会员卡余额");
recieveLabel = new JLabel("实收现金额");
rechargeLabel = new JLabel("充值数额");
cashCheckLabel = new JLabel("现金充值");
printCheckLabel = new JLabel("打印小单");
}
/*
* 初始化文本输入框
*/
public void initJTextFeild() {
nameField = new JTextField(10);
idField = new JTextField(10);
phoneField = new JTextField(10);
balanceField = new JTextField(10);
recieveFeild = new JTextField(10);
rechargeFeild = new JTextField(10);
}
/**
* 获取面板中余额区域的值
* @return
*/
public JTextField getBalanceField(){
return balanceField;
}
/**
* 获取面板中充值金额区域的值
* @return
*/
public JTextField getRechargeFeild(){
return rechargeFeild;
}
/**
* 初始化并且添加组件到infoPanel,返回构造好的infoPanel
*
* @return JPanel
*/
public JPanel buildInfoPanel() {
if (infoPanel == null) {
infoPanel = new JPanel();
infoPanel.setBorder(BorderFactory.createTitledBorder("会员信息"));
infoPanel.setLayout(new GridBagLayout());
infoPanel.add(nameLabel, new GBC(0, 0).setInset(5, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(nameField, new GBC(1, 0).setInset(5, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(idLabel, new GBC(2, 0).setInset(5, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(idField, new GBC(3, 0).setInset(5, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(phoneLabel, new GBC(0, 1).setInset(5, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(phoneField, new GBC(1, 1).setInset(5, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(balanceLabel, new GBC(2, 1).setInset(5, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(balanceField, new GBC(3, 1).setInset(5, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
}
return infoPanel;
}
/**
* 初始化rechargePanel并且添加组件到rechargePanel,返回构造好了的rechargePanel
*
* @return JPanel
*/
public JPanel buildRechargePanel() {
if (rechargePanel == null) {
rechargePanel = new JPanel();
rechargePanel.setBorder(BorderFactory.createTitledBorder("充值收款"));
rechargePanel.setLayout(new GridBagLayout());
rechargePanel.add(recieveLabel, new GBC(0, 0).setInset(5, 15, 5, 15).setFill(GBC.WEST));
rechargePanel.add(recieveFeild, new GBC(1, 0).setInset(5, 15, 5, 15).setWeight(4, 0)
.setFill(GBC.HORIZONTAL));
rechargePanel.add(rechargeLabel, new GBC(2, 0).setInset(5, 15, 5, 15).setFill(GBC.WEST));
rechargePanel.add(rechargeFeild, new GBC(3, 0).setInset(5, 15, 5, 15).setWeight(4, 0)
.setFill(GBC.HORIZONTAL));
}
return rechargePanel;
}
/**
* 初始化actionPanel并且添加组件到actionPanel,返回构造好了的actionPanel
*
* @return JPanel
*/
public JPanel buildActionPanel(JDialog dialog) {
if (actionPanel == null) {
actionPanel = new JPanel();
actionPanel.setBorder(BorderFactory.createTitledBorder("控制选项"));
actionPanel.add(buildCashCheck());
actionPanel.add(cashCheckLabel);
actionPanel.add(buildPrintCheck());
actionPanel.add(printCheckLabel);
actionPanel.add(buildButtonOk(dialog));
actionPanel.add(buildButtonCancel(dialog));
}
return actionPanel;
}
public JCheckBox buildCashCheck() {
if (cashCheck == null) {
cashCheck = new JCheckBox();
}
return cashCheck;
}
public JCheckBox buildPrintCheck() {
if (printCheck == null) {
printCheck = new JCheckBox();
}
return printCheck;
}
public JButton buildButtonOk(JDialog dialog) {
if (buttonOk == null) {
buttonOk = new JButton("确定");
if(managePanel != null){
buttonOk.addActionListener(new VipRechargePanelListener(this, managePanel,dialog));
}
}
return buttonOk;
}
public JButton buildButtonCancel(JDialog dialog) {
if (buttonCancel == null) {
buttonCancel = new JButton("取消");
buttonCancel.addActionListener(new VipRechargePanelListener(this,dialog));
}
return buttonCancel;
}
/**
* 检查该面板输入的信息是否符合条件,包括编号不含字符,必备条件非空,密码和密码确认匹配
*
* @return
*/
public boolean checkInput() {
if (CheckInputUtil.checkInputIsNull(recieveFeild.getText())) {
JOptionPane.showMessageDialog(null, "实收金额不能为空");
recieveFeild.requestFocus();
return false;
}
if (CheckInputUtil.checkIsContainCharactor(recieveFeild.getText())) {
JOptionPane.showMessageDialog(null, "实收金额输入只能为数字");
recieveFeild.setText("");
recieveFeild.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(rechargeFeild.getText())) {
JOptionPane.showMessageDialog(null, "充值金额不能为空");
rechargeFeild.requestFocus();
return false;
}
if (CheckInputUtil.checkIsContainCharactor(rechargeFeild.getText())) {
JOptionPane.showMessageDialog(null, "充值金额只能为数字");
rechargeFeild.setText("");
rechargeFeild.requestFocus();
return false;
}
if(Integer.parseInt(rechargeFeild.getText()) > Integer.parseInt(recieveFeild.getText())){
JOptionPane.showMessageDialog(null, "充值金额不能大于实收金额");
rechargeFeild.requestFocus();
return false;
}
return true;
}
/**
* @return the idField
*/
public JTextField getIdField() {
return idField;
}
/**
* @param idField the idField to set
*/
public void setIdField(JTextField idField) {
this.idField = idField;
}
/**
* 获得界面充值记录的值,并返回VipChargeVo
* @return
*/
public VipChargeVo getChargeValue() {
int vipId = Integer.parseInt(getIdField().getText());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd");
String chargeDate = sdf.format(new Date());
int chargeAmount = Integer.parseInt(rechargeFeild.getText());
int receiveAmount = Integer.parseInt(rechargeFeild.getText());
String operatorName = MainFrame.getOperatorName();
return new VipChargeVo(vipId, chargeDate, chargeAmount, receiveAmount, operatorName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -