📄 clothesadditionsetpanel.java
字号:
package view.panel.clothesAddition;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import view.common.GBC;
import vo.ClothesAccessoriesVo;
import vo.ClothesBrandsVo;
import vo.ClothesColorsVo;
import vo.ClothesFlawsVo;
import control.clothesAddition.ClothesAdditionSetListener;
import dao.clothesAdditionDao.ClothesAdditionDao;
import dao.clothesAdditionDao.additionDaoImpl.AdditionDaoImpl;
import dao.common.DbException;
public class ClothesAdditionSetPanel extends JPanel {
private JTable brandSetTable, accessoriesSetTable, colorSetTable,
flawSetTable;
private JTabbedPane tabbedPane;
private JButton addBtn, modifyBtn, deleteBtn, quitBtn;
public ClothesAdditionSetPanel() {
this.setLayout(new BorderLayout());
this.add(buildTabbedPane());
this.add(buildBtnPanel(), BorderLayout.EAST);
initialize();
}
public void initialize() {
ClothesAdditionDao dao = new AdditionDaoImpl();
try {
Vector brandsVecor = dao.getClothesBrands();
iniBrandsTable(brandsVecor);
Vector accessoriesVecor = dao.getClothesAccessoriess();
iniAccessoriesTable(accessoriesVecor);
Vector colorsVecor = dao.getClothesColors();
iniColorsTable(colorsVecor);
Vector flawsVecor = dao.getClothesFlaws();
iniFlawsTable(flawsVecor);
} catch (DbException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
public void iniBrandsTable(Vector brandsVecor) {
DefaultTableModel tableModel = (DefaultTableModel) this
.buildBrandSetTable().getModel();
Iterator it = brandsVecor.iterator();
while (it.hasNext()) {
ClothesBrandsVo brand = (ClothesBrandsVo) it.next();
Object[] content = { brand.getClothesBrand() };
tableModel.addRow(content);
}
}
public void iniAccessoriesTable(Vector accessoriesVecor) {
DefaultTableModel tableModel = (DefaultTableModel) this
.buildAccessoriesSetTable().getModel();
Iterator it = accessoriesVecor.iterator();
while (it.hasNext()) {
ClothesAccessoriesVo accessory = (ClothesAccessoriesVo) it.next();
Object[] content = { accessory.getAccessory() };
tableModel.addRow(content);
}
}
public void iniColorsTable(Vector colorsVecor) {
DefaultTableModel tableModel = (DefaultTableModel) this
.buildColorSetTable().getModel();
Iterator it = colorsVecor.iterator();
while (it.hasNext()) {
ClothesColorsVo color = (ClothesColorsVo) it.next();
Object[] content = { color.getColor() };
tableModel.addRow(content);
}
}
public void iniFlawsTable(Vector flawsVecor) {
DefaultTableModel tableModel = (DefaultTableModel) this
.buildFlawSetTable().getModel();
Iterator it = flawsVecor.iterator();
while (it.hasNext()) {
ClothesFlawsVo flaw = (ClothesFlawsVo) it.next();
Object[] content = { flaw.getFlaw() };
tableModel.addRow(content);
}
}
public JTabbedPane buildTabbedPane() {
if (tabbedPane == null) {
tabbedPane = new JTabbedPane();
tabbedPane.add("衣服品牌设置", buildClothesBrandSetPane());
tabbedPane.add("衣服附件设置", buildClothesAccessoriesSetPane());
tabbedPane.add("衣服颜色设置", buildClothesColorSetPane());
tabbedPane.add("衣服瑕疵设置", buildClothesFlawSetPane());
}
return tabbedPane;
}
public JScrollPane buildClothesBrandSetPane() {
return new JScrollPane(buildBrandSetTable());
}
public JTable buildBrandSetTable() {
if (brandSetTable == null) {
String[] tableHeaders = { "衣服品牌" };
Object[][] data = {};
DefaultTableModel tableModel = new DefaultTableModel(data,
tableHeaders) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
};
brandSetTable = new JTable(tableModel);
}
return brandSetTable;
}
public JScrollPane buildClothesAccessoriesSetPane() {
return new JScrollPane(buildAccessoriesSetTable());
}
public JTable buildAccessoriesSetTable() {
if (accessoriesSetTable == null) {
String[] tableHeaders = { "衣服附件" };
Object[][] data = {};
DefaultTableModel tableModel = new DefaultTableModel(data,
tableHeaders) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
};
accessoriesSetTable = new JTable(tableModel);
}
return accessoriesSetTable;
}
public JScrollPane buildClothesColorSetPane() {
return new JScrollPane(buildColorSetTable());
}
public JTable buildColorSetTable() {
if (colorSetTable == null) {
String[] tableHeaders = { "衣服颜色" };
Object[][] data = {};
DefaultTableModel tableModel = new DefaultTableModel(data,
tableHeaders) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
};
colorSetTable = new JTable(tableModel);
}
return colorSetTable;
}
public JScrollPane buildClothesFlawSetPane() {
return new JScrollPane(buildFlawSetTable());
}
public JTable buildFlawSetTable() {
if (flawSetTable == null) {
String[] tableHeaders = { "衣服瑕疵" };
Object[][] data = {};
DefaultTableModel tableModel = new DefaultTableModel(data,
tableHeaders) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
};
flawSetTable = new JTable(tableModel);
}
return flawSetTable;
}
public JPanel buildBtnPanel() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(buildAddBtn(), new GBC(0, 0, 1, 1).setInset(5));
panel.add(buildModifyBtn(), new GBC(0, 1, 1, 1).setInset(5));
panel.add(buildDeleteBtn(), new GBC(0, 2, 1, 1).setInset(5));
panel.add(buildQuitBtn(), new GBC(0, 3, 1, 1).setInset(50, 5, 50, 5));
return panel;
}
public JButton buildAddBtn() {
if (addBtn == null) {
addBtn = new JButton("添加");
addBtn.addActionListener(new ClothesAdditionSetListener(this));
}
return addBtn;
}
public JButton buildModifyBtn() {
if (modifyBtn == null) {
modifyBtn = new JButton("修改");
modifyBtn.addActionListener(new ClothesAdditionSetListener(this));
}
return modifyBtn;
}
public JButton buildDeleteBtn() {
if (deleteBtn == null) {
deleteBtn = new JButton("删除");
deleteBtn.addActionListener(new ClothesAdditionSetListener(this));
}
return deleteBtn;
}
public JButton buildQuitBtn() {
if (quitBtn == null) {
quitBtn = new JButton("退出");
}
return quitBtn;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f = new JFrame();
f.add(new ClothesAdditionSetPanel());
f.pack();
f.setSize(500, 400);
f.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -