📄 vipmodifypanel.java
字号:
package view.panel.vip;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import view.common.CheckInputUtil;
import view.common.GBC;
import vo.VipCardVo;
import vo.VipVo;
import control.vip.VipModifyPanelListener;
import dao.common.DbException;
import dao.common.sql.VipSql;
import dao.vip.VipDao;
import dao.vip.impl.VipDaoImpl;
public class VipModifyPanel extends JPanel {
// =====添加面板的两个子面板=====
JPanel infoPanel, buttonPanel;
// ----定义infoPanel中的组件-----
// (文本标签)客户编号,客户姓名, 客户性别, 客户生日, 客户电话, 客户密码,确认密码
JLabel consumerId, consumerName, consumerSex, consumerBirthday,
originalPsw, consumerPhone, consumerPassword, ensurePassword,
address;
// (文本标签)会员级别, 会员折扣, 会员卡积分,会员卡状态, 注册日期,其他信息
JLabel consumerGrade, consumerDiscount, cardMark, cardStatu, registerDate,
otherInfo;
// (文本输入框)编号,姓名,生日, 电话,密码,确认密码
JTextField idField, nameField, birthdayField, phoneField;
JPasswordField passwordField, ensurePswFiled, originalPswField;
// (文本输入框)折扣,积分,注册日期
JTextField discountField, markField, dateField, addressField;
// (组合框)性别,级别,状态
JComboBox sexCombo, gradeCombo, statuCombo;
// (文本域)其他信息
JTextArea otherInfoArea;
// -----定义buttonPanel中的组件-----
JButton buttonOk, buttonCancel;
// 需要用来与其他界面进行数据交互通信的属性
VipManagePanel managePanel;
VipVo vipVo;
// /**
// * 构造方法,设置面板的属性和添加的组件
// */
/**
* 构造方法,设置面板的属性和添加的组件
*/
public VipModifyPanel(VipManagePanel managePanel, JDialog dialog) {
// this.setSize(470, 360);
this.managePanel = managePanel;
// this.setBackground(Color.BLACK);
this.setLayout(new BorderLayout());
initComponent();
this.add(buildInfoPanel());
this.add(buildButtonPanel(dialog), BorderLayout.SOUTH);
}
/**
* 构造按钮面板(buttonPanel),并且设置布局
*
* @return JPanel
*/
public JPanel buildButtonPanel(JDialog dialog) {
if (buttonPanel == null) {
buttonPanel = new JPanel();
// buttonPanel.setBackground(Color.GREEN);
// buttonPanel.setLayout(new GridBagLayout());
buttonPanel.add(buildBtnOk(dialog));
buttonPanel.add(buildBtnCancel(dialog));
}
return buttonPanel;
}
public JButton buildBtnOk(JDialog dialog) {
if (buttonOk == null) {
buttonOk = new JButton("确定");
buttonOk.addActionListener(new VipModifyPanelListener(this,
managePanel, dialog));
}
return buttonOk;
}
public JButton buildBtnCancel(JDialog dialog) {
if (buttonCancel == null) {
buttonCancel = new JButton("取消");
buttonCancel.addActionListener(new VipModifyPanelListener(this,
managePanel, dialog));
}
return buttonCancel;
}
/**
* 将已经初始化的标签,文本输入框,文本域添加到信息面板,并且设置布局
*
* @return JPanel
*/
public JPanel buildInfoPanel() {
if (infoPanel == null) {
infoPanel = new JPanel();
infoPanel.setBorder(BorderFactory.createTitledBorder("会员信息"));
infoPanel.setLayout(new GridBagLayout());
infoPanel.setBorder(BorderFactory.createTitledBorder("会员信息"));
infoPanel.setLayout(new GridBagLayout());
infoPanel.add(consumerId, new GBC(0, 0).setInset(15, 20, 15, 20)
.setFill(GBC.WEST));
infoPanel.add(idField, new GBC(1, 0).setInset(15, 20, 15, 20)
.setWeight(5, 0).setFill(GBC.HORIZONTAL));
infoPanel.add(consumerName, new GBC(2, 0).setInset(15, 20, 15, 20)
.setFill(GBC.WEST));
infoPanel.add(nameField, new GBC(3, 0).setInset(15, 20, 15, 20)
.setWeight(5, 0).setFill(GBC.HORIZONTAL));
infoPanel.add(consumerSex, new GBC(0, 1).setInset(15, 20, 15, 20)
.setFill(GBC.WEST));
infoPanel.add(sexCombo, new GBC(1, 1).setInset(15, 20, 15, 20)
.setWeight(5, 0).setFill(GBC.HORIZONTAL));
infoPanel.add(consumerBirthday, new GBC(2, 1).setInset(15, 20, 15,
20).setFill(GBC.WEST));
infoPanel.add(this.birthdayField, new GBC(3, 1).setInset(15, 20,
15, 20).setWeight(5, 0).setFill(GBC.HORIZONTAL));
infoPanel.add(consumerPhone, new GBC(0, 2).setInset(15, 20, 15, 20)
.setFill(GBC.WEST));
infoPanel.add(phoneField, new GBC(1, 2).setInset(15, 20, 15, 20)
.setWeight(5, 0).setFill(GBC.HORIZONTAL));
infoPanel.add(originalPsw, new GBC(2, 2).setInset(15, 20, 15, 20)
.setFill(GBC.WEST));
infoPanel.add(originalPswField, new GBC(3, 2).setInset(15, 20, 15,
20).setWeight(5, 0).setFill(GBC.HORIZONTAL));
infoPanel.add(consumerPassword, new GBC(0, 3).setInset(15, 20, 15,
20).setFill(GBC.WEST));
infoPanel.add(passwordField, new GBC(1, 3).setInset(15, 20, 15, 20)
.setWeight(5, 0).setFill(GBC.HORIZONTAL));
infoPanel.add(ensurePassword, new GBC(2, 3)
.setInset(15, 20, 15, 20).setFill(GBC.WEST));
infoPanel.add(ensurePswFiled, new GBC(3, 3)
.setInset(15, 20, 15, 20).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(address, new GBC(0, 4).setInset(15, 20, 15, 20)
.setFill(GBC.WEST));
infoPanel.add(addressField, new GBC(1, 4, 3, 2)
.setFill(GBC.HORIZONTAL));
}
return infoPanel;
}
/*
* 初始化无需添加事件处理的组件,包括文本标签,文本输入框
*/
public void initComponent() {
initJLabel();
initJTextFeild();
initJComboBox();
initJTextArea();
if (managePanel == null || managePanel.getSelectedData() == null) {
} else {
initialComponentTableValue(managePanel.getSelectedData());
}
}
/**
*
* @param value
*/
public void initialComponentTableValue(String[] value) {
idField.setText(value[0]);
idField.setEditable(false);
nameField.setText(value[1]);
sexCombo.setSelectedItem(value[2]);
gradeCombo.setSelectedItem(value[3]);
statuCombo.setSelectedItem(value[6]);
phoneField.setText(value[7]);
markField.setText(value[8]);
birthdayField.setText(value[9]);
dateField.setText(value[10]);
dateField.setEditable(false);
addressField = new JTextField(10);
VipDao vipDao = new VipDaoImpl();
Vector v = null;
try {
v = vipDao.searchVipByKey(VipSql.SEARCH_BY_VIP_ID, value[0]);
if (v == null) {
return;
}
Iterator it = v.iterator();
while (it.hasNext()) {
this.vipVo = (VipVo) it.next();
}
} catch (DbException de) {
return;
}
addressField.setText(vipVo.getVipAddress());
/*
* "会员编号", "会员姓名", "会员性别", "会员级别", "会员卡号", "卡内余额", "会员卡状态", "联系手机",
* "会员积分", "会员生日", "注册时间"
*/
}
public boolean isOriginalPswRight() {
boolean flag = false;
if (vipVo.getVipCard().getVipPsw().equals(
String.valueOf(originalPswField.getPassword()))) {
flag = true;
System.out.println(vipVo.getVipCard().getVipPsw());
}
return flag;
}
public void clearOriginalPsw() {
originalPswField.setText("");
originalPswField.requestFocus();
}
/**
* 用提示信息初始化文本域
*/
public void initJTextArea() {
String info = "请再次输入其他的附加信息";
otherInfoArea = new JTextArea(info, 2, 10);
otherInfoArea.setRows(3);
}
/**
* 初始化组合框,列表选项赋值
*/
public void initJComboBox() {
String[] sex = { "男", "女" };
sexCombo = new JComboBox(sex);
sexCombo.setEditable(false);
String[] grade = { "普通", "中级", "高级" };
gradeCombo = new JComboBox(grade);
String[] statu = { "正常", "暂停", "停用" };
statuCombo = new JComboBox(statu);
}
/**
* 初始化文本框,并且给予大小
*/
public void initJTextFeild() {
idField = new JTextField(10);
nameField = new JTextField(10);
nameField.setEditable(false);
birthdayField = new JTextField(10);
birthdayField.setEditable(false);
phoneField = new JTextField(10);
passwordField = new JPasswordField(10);
ensurePswFiled = new JPasswordField(10);
originalPswField = new JPasswordField(10);
discountField = new JTextField(10);
markField = new JTextField(10);
dateField = new JTextField(10);
}
/**
* 初始化面板中标签属性
*/
public void initJLabel() {
consumerId = new JLabel("会员编号");
consumerName = new JLabel("会员名称");
consumerSex = new JLabel("会员性别");
consumerBirthday = new JLabel("会员生日");
consumerPhone = new JLabel("会员电话");
consumerPassword = new JLabel("新定密码");
ensurePassword = new JLabel("密码确认");
originalPsw = new JLabel("原始密码");
consumerGrade = new JLabel("会员级别");
consumerDiscount = new JLabel("会员折扣");
cardMark = new JLabel("会员卡积分");
cardStatu = new JLabel("会员卡状态");
registerDate = new JLabel("注册日期");
otherInfo = new JLabel("其他信息:");
address = new JLabel("地址:");
}
/**
* 获得界面输入的值,以VipVo对象的形式传递给调用者
*
* @return VipVo
*/
public VipVo getInputTxtValue() {
String sex = sexCombo.getSelectedItem().toString();
String phone = phoneField.getText();
String address = addressField.getText().toString();
String newPsw = String.valueOf(passwordField.getPassword());
vipVo.setVipSex(sex);
vipVo.setVipPhone(phone);
vipVo.setVipAddress(address);
vipVo.getVipCard().setVipPsw(newPsw);
return vipVo;
}
/**
* 检查该面板输入的信息是否符合条件,包括编号不含字符,必备条件非空,密码和密码确认匹配
*
* @return
*/
public boolean checkInput() {
if (CheckInputUtil.checkInputIsNull(String.valueOf(originalPswField
.getPassword()))) {
JOptionPane.showMessageDialog(null, "请输入密码(小于16位)");
originalPswField.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(String.valueOf(passwordField
.getPassword()))) {
JOptionPane.showMessageDialog(null, "请输入密码(小于16位)");
passwordField.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(String.valueOf(ensurePswFiled
.getPassword()))) {
JOptionPane.showMessageDialog(null, "请输入密码校验(小于16位)");
ensurePswFiled.requestFocus();
return false;
}
if (!String.valueOf(ensurePswFiled.getPassword()).equals(
String.valueOf(passwordField.getPassword()))) {
JOptionPane.showMessageDialog(null, "请确定输入的密码和密码确认一致");
passwordField.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(phoneField.getText())) {
JOptionPane.showMessageDialog(null, "联系电话不能为空");
phoneField.requestFocus();
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -