📄 stockfinddialog.java
字号:
package view.dialog;
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.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import view.com.CenterDialog;
import view.com.GBC;
import view.com.calendar.DataPicker;
import view.com.getcomponent.button.GetButton;
import action.implementclass.dialogaction.StockFindAction;
public class StockFindDialog extends JDialog{
/**
* stockFindDialog 进货查找对话框
* product_id 商品编号文本框
* product_name 商品名称文本框
* txtStoreDate 进货时间
* product_type 商品类型文本框
* product_idBtn 商品编号按钮
* product_nameBtn 商品名称按钮
* product_typeBtn 商品类型按钮
* txtStoreDateBtn 进货时间按钮
* picker
* btnPanel 按钮面板
* panel
* table 表格
* button 按钮数组
* names 字符串数组
*/
private JDialog stockFindDialog;
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 JPanel btnPanel;
private JPanel panel;
public static JTable table;
private JButton[] button;
private String[] names = { "显示全部", "确定", "条件重置", "取消" };
private String[] icon={"icon\\button\\显示全部.GIF","icon\\button\\确定.GIF","icon\\button\\重置.GIF","icon\\button\\取消.GIF"};
private String[] argActionCommand = { "显示全部","确定", "条件重置", "取消"};
public StockFindDialog() {
stockFindDialog = new JDialog();
stockFindDialog.setTitle("进货查询");
stockFindDialog.setLayout(new BorderLayout());
stockFindDialog.add(getAddPanel(), BorderLayout.NORTH);
stockFindDialog.add(getJScrollPanel(), BorderLayout.CENTER);
stockFindDialog.setSize(640, 480);
new CenterDialog().getCenterDialog(stockFindDialog, true);
stockFindDialog.setVisible(true);
}
/**
* 获得addPanel面板
* @return addPanel 面板
*/
public JPanel getAddPanel() {
JPanel addPanel = new JPanel();
addPanel.setLayout(new BorderLayout());
addPanel.add(getPanel(), BorderLayout.NORTH);
addPanel.add(getBtnPanel(), BorderLayout.CENTER);
addPanel.setBorder(BorderFactory.createTitledBorder("进货查询"));
return addPanel;
}
public void getStockFindAction() {
}
/**
* 初始化各种文本框
*/
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.setEditable(false);
product_type.addItem("日常用品类");
product_type.addItem("家用电器类");
product_type.addItem("书籍资料类");
product_type.addItem("蔬菜水果类");
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);
}
/**
* 获得panel面板
* @return panel 面板
*/
public JPanel getPanel() {
panel = new JPanel();
this.initialText();
this.initialComboBox();
this.initialCheckBox();
panel.setLayout(new GridBagLayout());
panel.add(this.product_idBtn, new GBC(0, 1).setFill(GBC.WEST));
panel.add(this.product_id, new GBC(1, 1).setInset(7).setWeight(3, 0));
panel.add(this.product_nameBtn, new GBC(0, 2).setFill(GBC.WEST));
panel.add(this.product_name, new GBC(1, 2).setInset(7).setWeight(3, 0));
panel.add(this.product_typeBtn, new GBC(0, 3).setFill(GBC.WEST));
panel.add(this.product_type, new GBC(1, 3).setInset(7).setWeight(3, 0));
panel.add(this.txtStoreDateBtn, new GBC(0, 4).setFill(GBC.WEST));
panel.add(this.txtStoreDate, new GBC(1, 4).setInset(7).setWeight(3, 0)
.setFill(GBC.HORIZONTAL));
return panel;
}
/**
* 获得分割面板
* @return sp 分割面板
*/
public JScrollPane getJScrollPanel() {
JScrollPane sp = new JScrollPane(getJTable());
return sp;
}
/**
* 获得表格
* @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;
}
/**
* 获得按钮面板
* @return btnPanel 按钮面板
*/
public JPanel getBtnPanel() {
btnPanel = new JPanel();
button = new JButton[names.length];
button = new GetButton().getButton(button, names, icon, argActionCommand);
btnPanel.add(button[0]);
button[0].addActionListener(new StockFindAction());
btnPanel.add(button[1]);
button[1].addActionListener(new StockFindAction());
btnPanel.add(button[2]);
button[2].addActionListener(new StockFindAction());
btnPanel.add(button[3]);
button[3].addActionListener(new StockFindAction());
btnPanel.setBorder(BorderFactory.createTitledBorder("按钮组"));
return btnPanel;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -