📄 vipchangecardpanel.java
字号:
package view.panel.vip;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import view.common.CheckInputUtil;
import view.common.GBC;
import control.vip.VipChangeCardPanelListener;
public class VipChangeCardPanel extends JPanel {
// =====该面板的构成面板,信息面板,按钮面板=====
JPanel infoPanel, changePanel, buttonPanel;
// -----infoPanel(会员信息面板)的组件-----
// (文本标签)客户编号,客户姓名,客户电话,客户级别,卡内余额, 会员卡积分
JLabel consumerId, consumerName, consumerPhone, consumerGrade, cardBalance, cardMark;
// (文本输入框)编号,姓名,生日, 电话,密码,确认密码
JTextField idField, nameField, phoneField, gradeField, balanceField, markField;
// -----cardChangePanel(换卡信息面板)-----
// (文本标签)旧卡密码,新卡编号,新卡密码,确认新密码
JLabel oldCardPsw, /*newCardId,*/ newCardPsw, newPswEnsure;
// (文本输入框)旧卡密码,新卡卡号,新卡密码,确认新密码
/*JTextField newCardIdField;*/
JPasswordField oldPswField, newPswField, newPswFieldEnsure;
// -----buttonPanel(会员换卡按钮面板)的组件-----
JButton buttonOk, buttonCancel;
// 需要用来与其他界面进行数据交互通信的属性
VipManagePanel managePanel;
/**
* 构造方法二
*
*/
public VipChangeCardPanel(JDialog dialog) {
this.managePanel = managePanel;
this.setSize(470, 330);
this.setLayout(new BorderLayout());
initComponent();
this.add(buildInfoPanel(), BorderLayout.NORTH);
this.add(buildChangePanel());
this.add(buildButtonPanel(dialog), BorderLayout.SOUTH);
}
/**
* 构造方法二
*
*/
public VipChangeCardPanel(VipManagePanel managePanel, JDialog dialog) {
this.managePanel = managePanel;
this.setSize(470, 330);
this.setLayout(new BorderLayout());
initComponent();
this.add(buildInfoPanel(), BorderLayout.NORTH);
this.add(buildChangePanel());
this.add(buildButtonPanel(dialog), BorderLayout.SOUTH);
}
/**
* 初始化infoPanel,并且对其中的组件进行布局
*
* @return JPanel
*/
public JPanel buildInfoPanel() {
if (infoPanel == null) {
infoPanel = new JPanel();
infoPanel.setLayout(new GridBagLayout());
infoPanel.setBorder(BorderFactory.createTitledBorder("会员卡信息"));
infoPanel.add(consumerId, new GBC(0, 0).setInset(10, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(idField, new GBC(1, 0).setInset(10, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(consumerName, new GBC(2, 0).setInset(10, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(nameField, new GBC(3, 0).setInset(10, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(consumerPhone, new GBC(0, 1).setInset(10, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(phoneField, new GBC(1, 1).setInset(10, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(consumerGrade, new GBC(2, 1).setInset(10, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(gradeField, new GBC(3, 1).setInset(10, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(cardBalance, new GBC(0, 2).setInset(10, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(balanceField, new GBC(1, 2).setInset(10, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
infoPanel.add(cardMark, new GBC(2, 2).setInset(10, 15, 5, 15).setFill(GBC.WEST));
infoPanel.add(markField, new GBC(3, 2).setInset(10, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
}
return infoPanel;
}
/**
* 初始化changePanel,并且对其中的组件进行布局
*
* @return JPanel
*/
public JPanel buildChangePanel() {
if (changePanel == null) {
changePanel = new JPanel();
changePanel.setLayout(new GridBagLayout());
changePanel.setBorder(BorderFactory.createTitledBorder("换卡输入"));
changePanel.add(oldCardPsw, new GBC(0, 0).setInset(5, 15, 5, 15).setFill(GBC.WEST));
changePanel.add(oldPswField, new GBC(1, 0).setInset(5, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
changePanel.add(newCardPsw, new GBC(0, 1).setInset(5, 15, 5, 15).setFill(GBC.WEST));
changePanel.add(newPswField, new GBC(1, 1).setInset(5, 15, 5, 15).setWeight(5, 0).setFill(
GBC.HORIZONTAL));
changePanel.add(newPswEnsure, new GBC(2, 1).setInset(5, 15, 5, 15).setFill(GBC.WEST));
changePanel.add(newPswFieldEnsure, new GBC(3, 1).setInset(5, 15, 5, 15).setWeight(5, 0)
.setFill(GBC.HORIZONTAL));
}
return changePanel;
}
/**
* 构造buttonPanel并且返回添加了组件的buttonPanel
*
* @return JPanel
*/
public JPanel buildButtonPanel(JDialog dialog) {
if (buttonPanel == null) {
buttonPanel = new JPanel();
buttonPanel.add(buildButtonOk());
buttonPanel.add(buildButtonCancel(dialog));
}
return buttonPanel;
}
public JButton buildButtonOk() {
if (buttonOk == null) {
buttonOk = new JButton("确定");
buttonOk.addActionListener(new VipChangeCardPanelListener(this, managePanel));
}
return buttonOk;
}
public JButton buildButtonCancel(JDialog dialog) {
if (buttonCancel == null) {
buttonCancel = new JButton("取消");
buttonCancel.addActionListener(new VipChangeCardPanelListener(this, managePanel,dialog));
}
return buttonCancel;
}
/**
* 初始化不需要添加监听事件的组件
*/
public void initComponent() {
initJLabel();
initJTextFeild();
initJPasswordFeild();
initialComponentTableValue(managePanel.getSelectedData());
}
/**
*
* @param value
*/
public void initialComponentTableValue(String[] value) {
idField.setText(value[0]);
nameField.setText(value[1]);
gradeField.setText(value[3]);
balanceField.setText(value[5]);
phoneField.setText(value[7]);
markField.setText(value[8]);
idField.setEditable(false);
nameField.setEditable(false);
phoneField.setEditable(false);
gradeField.setEditable(false);
balanceField.setEditable(false);
markField.setEditable(false);
}
/*
* "会员编号", "会员姓名", "会员性别", "会员级别",
* "会员卡号", "卡内余额", "会员卡状态", "联系手机",
* "会员积分", "会员生日", "注册时间"
*/
/**
* 初始化整个面板中的密码输入框
*/
public void initJPasswordFeild() {
oldPswField = new JPasswordField(10);
newPswField = new JPasswordField(10);
newPswFieldEnsure = new JPasswordField(10);
}
/**
* 初始化面板中标签属性
*/
public void initJLabel() {
consumerId = new JLabel("会员编号");
consumerName = new JLabel("会员称呼");
consumerPhone = new JLabel("会员电话");
consumerGrade = new JLabel("会员级别");
cardBalance = new JLabel("会员卡余额");
cardMark = new JLabel("会员卡积分");
oldCardPsw = new JLabel("旧卡密码");
newCardPsw = new JLabel("新卡密码");
newPswEnsure = new JLabel("确认新密码");
}
/**
* 初始化文本输入框
*/
public void initJTextFeild() {
idField = new JTextField(10);
nameField = new JTextField(10);
phoneField = new JTextField(10);
gradeField = new JTextField(10);
balanceField = new JTextField(10);
markField = new JTextField(10);
}
/**
* 检查该面板输入的信息是否符合条件,包括编号不含字符,必备条件非空,密码和密码确认匹配
*
* @return
*/
public boolean checkInput() {
if (CheckInputUtil.checkInputIsNull(String.valueOf(oldPswField.getPassword()))) {
JOptionPane.showMessageDialog(null, "请输入旧卡密码(小于16位)");
oldPswField.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(String.valueOf(newPswField.getPassword()))) {
JOptionPane.showMessageDialog(null, "请输入新卡密码(小于16位)");
newPswField.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(String.valueOf(newPswFieldEnsure.getPassword()))) {
JOptionPane.showMessageDialog(null, "请输入新卡密码校验(小于16位)");
newPswFieldEnsure.requestFocus();
return false;
}
if (!String.valueOf(newPswField.getPassword()).equals(
String.valueOf(newPswFieldEnsure.getPassword()))) {
JOptionPane.showMessageDialog(null, "请确定输入的密码和密码确认一致");
newPswField.requestFocus();
return false;
}
return true;
}
/**
* @return the newPswField
*/
public JPasswordField getNewPswField() {
return newPswField;
}
/**
* @return the idField
*/
public JTextField getIdField() {
return idField;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -