📄 vipaddaction.java
字号:
package action.implementclass.dialogaction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import view.dialog.VipAddDialog;
import view.dialog.basedialog.VipBaseDialog;
import view.dialog.dialogoper.VipBaseOper;
import vo.VipVo;
import common.jdbc.DbException;
import dao.VipDao;
public class VipAddAction implements ActionListener{
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("确定")) {
if (VipBaseOper.checkInputValue()) {
VipVo value = VipBaseOper.getInputTextValue();
VipDao dao = new VipDao();
try {
if (dao.insertVip(value)) {
JOptionPane.showMessageDialog(null, "数据添加成功", "Info",
JOptionPane.YES_OPTION);
// 获得JTable的数据模型
DefaultTableModel tableModel = (DefaultTableModel) VipBaseDialog.table.getModel();
// 将要加入的JTable中的数据构造为一个一维数组
Object[] data = { new Integer(value.getVip_id()),
value.getVip_name(), value.getVip_type(),
value.getPrice_pct(), new Long(value.getPhone()) };
// 通过DefaultTableModel模型将数据增加到JTable对象中
tableModel.addRow(data);
}
} catch (DbException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error",
JOptionPane.YES_OPTION);
}
}
} else if (e.getActionCommand().equals("取消")) {
VipAddDialog.vipAddDialog.dispose();
} else if (e.getActionCommand().equals("重置")) {
VipBaseOper.initialTextValue();
} else if (e.getActionCommand().equals("刷新")) {
Vector v = new VipDao().getVipInfo();
Iterator iter = v.iterator();
DefaultTableModel tableModel = (DefaultTableModel) VipBaseDialog.table.getModel();
int counts = tableModel.getRowCount();
// 循环删除jtable中的所有数据
for (int i = counts - 1; i >= 0; i--) {
tableModel.removeRow(i);
}
while (iter.hasNext()) {
VipVo value = (VipVo) iter.next();
Object[] data = { new Integer(value.getVip_id()),
value.getVip_name(), value.getVip_type(),
value.getPrice_pct(), new Long(value.getPhone()),
};
tableModel.addRow(data);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -