增加备注

branch_sgl
沈国良 9 months ago
parent b319190310
commit af3748a228

@ -29,166 +29,153 @@ import com.lingnan.supermarket.table.StorageTableModel;
import com.lingnan.supermarket.table.UserTableModel;
import com.lingnan.supermarket.utils.FontUtil;
public class ProdCatalogView extends JPanel {
// 上面
private JPanel toolBarPanel;
private JPanel searchPanel;
private JLabel logLabel, locationLabel;
private JTextField nameSearchTF;
private JButton searchBtn;
private JPanel opePanel;
private JButton addBtn, updateBtn, deleteBtn;
private String catalog = "0";
private JComboBox<String> combo;
private String log[]=null;
private ArrayList<String>alog=null;
private ProdCatalogTM prodCatalogTM;
private ProdCatalog pc;
private prodCatalogImpl pci;
// 中间
private JScrollPane tableScrollPane;
private JTable prodCatalogTable;
// 下面
private JPanel bottomPanel;
private JLabel countInfoLabel;
private JFrame jFrame;
// 商品目录界面类,继承 JPanel
public class ProdCatalogView extends JPanel {
// ==== 顶部组件 ====
private JPanel toolBarPanel; // 工具栏面板
private JPanel searchPanel; // 搜索面板
private JLabel logLabel; // 分类标签
private JLabel locationLabel; // 位置标签
private JTextField nameSearchTF; // 搜索文本框
private JButton searchBtn; // 搜索按钮
private JPanel opePanel; // 操作面板
private JButton addBtn; // 添加按钮
private JButton updateBtn; // 更新按钮
private JButton deleteBtn; // 删除按钮
// 分类相关
private String catalog = "0"; // 当前目录ID默认值为 0
private JComboBox<String> combo; // 分类选择下拉框
private String[] log = null; // 分类名称数组
private ArrayList<String> alog = null; // 分类名称列表
private ProdCatalogTM prodCatalogTM; // 商品目录表模型
private ProdCatalog pc; // 商品目录对象
private prodCatalogImpl pci; // 商品目录操作实现类
// ==== 中间表格组件 ====
private JScrollPane tableScrollPane; // 表格滚动面板
private JTable prodCatalogTable; // 商品目录表
// ==== 底部组件 ====
private JPanel bottomPanel; // 底部面板
private JLabel countInfoLabel; // 记录数信息标签
// 窗口
private JFrame jFrame; // 主窗口
// 构造函数
public ProdCatalogView(JFrame jFrame) {
// 设置布局管理器
this.setLayout(new BorderLayout());
// 初始化界面
initView();
// 赋值 JFrame
this.jFrame = jFrame;
}
// 初始化界面组件的方法
private void initView() {
toolBarPanel = new JPanel(new BorderLayout());
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
locationLabel = new JLabel("商品目录");
locationLabel.setFont(new FontUtil().userFont);
locationLabel.setForeground(new Color(18, 150, 219));
logLabel = new JLabel("分类");
nameSearchTF = new JTextField(10);
// ==== 工具栏面板 ====
toolBarPanel = new JPanel(new BorderLayout()); // 初始化工具栏面板
searchBtn = new JButton("搜索", new ImageIcon("static\\icon\\search.png"));
// 初始化搜索面板
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 搜索面板左对齐
locationLabel = new JLabel("商品目录"); // 初始化位置标签
locationLabel.setFont(new FontUtil().userFont); // 设置自定义字体
locationLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色
// opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// addBtn = new JButton(new ImageIcon("static\\icon\\add.png"));
// updateBtn = new JButton(new ImageIcon("static\\icon\\update.png"));
// deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png"));
logLabel = new JLabel("分类"); // 初始化分类标签
nameSearchTF = new JTextField(10); // 初始化文本框,长度 10
// addBtn.addActionListener(this);
// updateBtn.addActionListener(this);
// deleteBtn.addActionListener(this);
searchBtn = new JButton("搜索", new ImageIcon("static\\icon\\search.png")); // 创建搜索按钮
// opePanel.add(addBtn);
// opePanel.add(updateBtn);
// opePanel.add(deleteBtn);
pci=new prodCatalogImpl();
this.alog=pci.findNameProdCatalog();
this.log=new String[alog.size()];
for(int i=0;i<alog.size();i++)
log[i]=alog.get(i);
for(int i=0;i<log.length;i++)
{
System.out.println(log[i]);
// 商品目录实现类
pci = new prodCatalogImpl();
// 查询分类名称列表
this.alog = pci.findNameProdCatalog();
this.log = new String[alog.size()]; // 初始化数组
for (int i = 0; i < alog.size(); i++) {
log[i] = alog.get(i); // 填充数组
}
// 调试输出:打印分类
for (int i = 0; i < log.length; i++) {
System.out.println("分类名称:" + log[i]);
}
// 初始化下拉框
combo = new JComboBox<String>(log);
// 添加事件监听器
combo.addItemListener(new MyItemListener());
// 将组件添加到搜索面板
searchPanel.add(locationLabel);
searchPanel.add(logLabel);
searchPanel.add(combo);
/*
* searchPanel.add(nameSearchTF); searchPanel.add(searchBtn);
*/
// 将搜索面板添加到工具栏
toolBarPanel.add(searchPanel, "West");
// toolBarPanel.add(opePanel, "East");
// 中间表格
prodCatalogTM = new ProdCatalogTM();
prodCatalogTM.all();
prodCatalogTable = new JTable(prodCatalogTM);
prodCatalogTable.setFont(FontUtil.tableFont);
prodCatalogTable.setRowHeight(50);
tableScrollPane = new JScrollPane(prodCatalogTable);
// ==== 中间表格 ====
prodCatalogTM = new ProdCatalogTM(); // 初始化表格模型
prodCatalogTM.all(); // 查询所有数据
prodCatalogTable = new JTable(prodCatalogTM); // 创建表格
prodCatalogTable.setFont(FontUtil.tableFont); // 设置字体
prodCatalogTable.setRowHeight(50); // 设置行高
tableScrollPane = new JScrollPane(prodCatalogTable); // 将表格包装为滚动面板
// 下面
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
countInfoLabel = new JLabel("总共" + prodCatalogTable.getRowCount() + "条");
bottomPanel.add(countInfoLabel);
// ==== 底部面板 ====
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 左对齐
countInfoLabel = new JLabel("总共" + prodCatalogTable.getRowCount() + "条记录"); // 显示总记录数
bottomPanel.add(countInfoLabel); // 添加记录数标签
// 将各个组件添加到主面板
this.add(toolBarPanel, "North");
this.add(tableScrollPane, "Center");/* 将表格放到中间 */
this.add(tableScrollPane, "Center");
this.add(bottomPanel, "South");
// 设置可见
setVisible(true);
}
// @Override
// public void actionPerformed(ActionEvent e) {
// Object source = e.getSource();
// if (addBtn == source) {
// UserDialog userDialog = new UserDialog(jFrame);
// userDialog.setVisible(true);
// } else if (updateBtn == source) {
//
// } else if (deleteBtn == source) {
//
// }
// }
// 下拉框监听器类
public class MyItemListener implements ItemListener {
@Override
public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox) e.getSource();
String catalog1 = (String) cb.getSelectedItem();
pci =new prodCatalogImpl();
for(int i=0;i<log.length;i++){
if(catalog1.equals(log[i]))
catalog=pci.findProdCatalogByname(catalog1);
System.out.println(catalog);
JComboBox cb = (JComboBox) e.getSource(); // 获取事件源
String catalog1 = (String) cb.getSelectedItem(); // 获取选中的分类名称
pci = new prodCatalogImpl(); // 重新实例化商品目录实现类
for (int i = 0; i < log.length; i++) {
if (catalog1.equals(log[i])) {
catalog = pci.findProdCatalogByname(catalog1); // 根据名称查找分类ID
}
System.out.println("当前目录:" + catalog); // 打印当前分类ID
}
refreshFindId2();
refreshFindId2(); // 刷新界面
}
}
// 刷新当前界面
// 刷新界面
public void refreshFindId2() {
Production p = new Production();
p.setId2(catalog);
prodCatalogTM = new ProdCatalogTM();
prodCatalogTM.ById2(p);
prodCatalogTable.setModel(prodCatalogTM);
// 同时更新下面的记录数
refreshCount();
Production p = new Production(); // 创建生产对象
p.setId2(catalog); // 设置分类ID
prodCatalogTM = new ProdCatalogTM(); // 初始化表格模型
prodCatalogTM.ById2(p); // 根据分类加载数据
prodCatalogTable.setModel(prodCatalogTM); // 更新表格模型
refreshCount(); // 更新记录数
}
// 更新记录数
public void refreshCount() {
bottomPanel.removeAll();
countInfoLabel = new JLabel("总共" + prodCatalogTM.getRowCount() + "条");
bottomPanel.add(countInfoLabel);
bottomPanel.removeAll(); // 清空底部面板
countInfoLabel = new JLabel("总共" + prodCatalogTM.getRowCount() + "条记录"); // 更新标签
bottomPanel.add(countInfoLabel); // 添加标签
}
}
}

Loading…
Cancel
Save