⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getstorepanel.java

📁 好的超市源码供大家下载
💻 JAVA
字号:
package view.panel.subpanel;

import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import view.com.GBC;
import view.com.calendar.DataPicker;
import view.com.getcomponent.button.GetButton;
import action.implementclass.panelaction.StorePanelAction;

/**
 * 存货面板
 * @author linfeng
 *
 */
public class GetStorePanel extends JPanel {

  /**
   * product_id 商品编号
   * product_name 商品名称
   * product_type 商品类型
   * txtSaleDate 售出时间
   * product_idBtn 商品编号单选按钮
   * product_nameBtn 商品名称单选按钮
   * product_typeBtn 商品类型单选按钮
   * txtStoreDateBtn 售出时间单选按钮
   * picker
   * leftPanel 左面板
   * rightPanel 右面板
   * table 表格
   * js 分割面板
   * sp 滚动条面板
   * vBox 垂直Box
   * button 按钮数组
   * names 字符串数组
   */
  public static JTextField product_id, product_name;
  public static JComboBox txtStoreDate = null, product_type;
  public static JRadioButton product_idBtn, product_nameBtn,
      product_typeBtn, txtStoreDateBtn;
  private DataPicker picker = new DataPicker();
  private JSplitPane js;
  private JPanel leftPanel, rightPanel;
  public static JTable table;
  private JScrollPane sp;
  private Box vBox;
  private JButton[] button;
  private String[] names = { "显示全部","条件重置","快速查询", "打印结果", "打印存货单" };

  /**
   * 初始化各种组件
   */
  public void initialText() {
    this.product_id = new JTextField(12);
    this.product_id.setEditable(false);
    this.product_name = new JTextField(12);
    this.product_name.setEditable(false);
    this.txtStoreDate = picker.getDataPacker();
    this.txtStoreDate.setEnabled(false);
  }

  /**
   * 初始化product_type下拉框
   * @return product_type 下拉框
   */
  public JComboBox initialComboBox() {
    product_type = new JComboBox();
    product_type.setEnabled(false);
    this.product_type.addItem("日常用品类");
    this.product_type.addItem("家用电器类");
    this.product_type.addItem("书籍资料类");
    this.product_type.addItem("蔬菜水果类");
    this.product_type.addItem("副食品类");
    return product_type;
  }

  /**
   * 初始化各种复选框
   */
  public void initialCheckBox() {
    ButtonGroup bg = new ButtonGroup();
    product_idBtn = new JRadioButton("按商品编号查询");
    product_idBtn.addItemListener(new ItemListener() {

      public void itemStateChanged(ItemEvent e) {
        if (product_idBtn.isSelected()) {
          product_id.setEditable(true);
        } else {
          product_id.setEditable(false);
        }

      }
    });
    bg.add(product_idBtn);
    product_nameBtn = new JRadioButton("按商品名称查询");
    product_nameBtn.addItemListener(new ItemListener() {

      public void itemStateChanged(ItemEvent e) {
        if (product_nameBtn.isSelected()) {
          product_name.setEditable(true);
        } else {
          product_name.setEditable(false);
        }

      }
    });
    bg.add(product_nameBtn);
    product_typeBtn = new JRadioButton("按商品类别查询");
    product_typeBtn.addItemListener(new ItemListener() {

      public void itemStateChanged(ItemEvent e) {
        if (product_typeBtn.isSelected()) {
          product_type.setEnabled(true);
        } else {
          product_type.setEnabled(false);
        }

      }
    });
    bg.add(product_typeBtn);
    txtStoreDateBtn = new JRadioButton("按存货日期查询");
    txtStoreDateBtn.addItemListener(new ItemListener() {

      public void itemStateChanged(ItemEvent e) {
        if (txtStoreDateBtn.isSelected()) {
          txtStoreDate.setEnabled(true);
        } else {
          txtStoreDate.setEnabled(false);
        }

      }
    });
    bg.add(txtStoreDateBtn);
  }

  /**
   * 初始化rightPanel面板信息
   * @return rightPanel 右面板
   */
  public JPanel initialInfo() {
    this.initialText();
    this.initialComboBox();
    this.initialCheckBox();
    rightPanel = new JPanel();
    rightPanel.setLayout(new GridBagLayout());
    rightPanel.add(this.product_idBtn, new GBC(0, 1).setFill(GBC.WEST));
    rightPanel.add(this.product_id, new GBC(1, 1).setInset(7).setWeight(3, 0));
    rightPanel.add(this.product_nameBtn, new GBC(0, 2).setFill(GBC.WEST));
    rightPanel
        .add(this.product_name, new GBC(1, 2).setInset(7).setWeight(3, 0));
    rightPanel.add(this.product_typeBtn, new GBC(0, 3).setFill(GBC.WEST));
    rightPanel
        .add(this.product_type, new GBC(1, 3).setInset(7).setWeight(3, 0));
    rightPanel.setBorder(BorderFactory.createTitledBorder("学生信息查找"));
    rightPanel.add(this.txtStoreDateBtn, new GBC(0, 4).setFill(GBC.WEST));
    rightPanel.add(this.txtStoreDate, new GBC(1, 4).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));
    rightPanel.setBorder(BorderFactory.createTitledBorder("快速查询"));
    return rightPanel;
  }

  /**
   * 获得table表格
   * @return table 表格
   */
  public JTable getJTable() {
    if (table == null) {
      Object[][] data = {};
      String[] name = { "商品编号", "商品名称", "商品类别", "商品价格", "进货数量", "进货日期" };
      DefaultTableModel model = new DefaultTableModel(data, name){
        public boolean isCellEditable(int row , int column){
          return false;
        }
      };
      table = new JTable(model);
    }
    return table;
  }

  /**
   * 获得sp滚动条面板
   * @return sp 滚动条面板
   */
  public JScrollPane getJScrollPanel() {
    sp = new JScrollPane(getJTable());
    return sp;
  }

  /**
   * 获得leftPanel按钮面板
   * @return leftPanel 按钮面板
   */
  public JPanel getBtnPanel() {
    leftPanel = new JPanel();
    button = new GetButton().getButton(button, names);
    vBox = Box.createVerticalBox();
    vBox.add(vBox.createVerticalStrut(15));
    vBox.add(button[0]);
    button[0].addActionListener(new StorePanelAction());
    button[0].setToolTipText(names[0]);
    vBox.add(vBox.createVerticalStrut(15));
    vBox.add(button[1]);
    button[1].addActionListener(new StorePanelAction());
    button[1].setToolTipText(names[1]);
    vBox.add(vBox.createVerticalStrut(15));
    vBox.add(button[2]);
    button[2].addActionListener(new StorePanelAction());
    button[2].setToolTipText(names[2]);
    vBox.add(vBox.createVerticalStrut(15));
    vBox.add(button[3]);
    button[3].addActionListener(new StorePanelAction());
    button[3].setToolTipText(names[3]);
    vBox.add(vBox.createVerticalStrut(15));
    vBox.add(button[4]);
    button[4].addActionListener(new StorePanelAction());
    button[4].setToolTipText(names[4]);
    BorderLayout bl = new BorderLayout();
    leftPanel.add(vBox, bl.CENTER);
    leftPanel.setBorder(BorderFactory.createTitledBorder("按钮组"));
    return leftPanel;
  }

  public GetStorePanel() {
    this.setLayout(new BorderLayout());
    this.add(initialInputActionPanel(), "North");
    this.add(getJScrollPanel());
  }

  /**
   * 获得js分割面板
   * @return js 分割面板
   */
  public JSplitPane initialInputActionPanel() {
    js = new JSplitPane();
    js.setRightComponent(initialInfo());
    js.setLeftComponent(getBtnPanel());
    return js;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -