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

📄 clothespricesetpanel.java

📁 一个优秀的干洗店管理系统
💻 JAVA
字号:
package view.panel.clothesType;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
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 vo.ClothesTypeVo;
import dao.clothesTypeDao.ClothesTypeDao;
import dao.clothesTypeDao.clothesTypeDaoImpl.ClothesTypeDaoImpl;
import dao.common.DbException;

public class ClothesPriceSetPanel extends JPanel{
	private JTextField keywordTxFld;
	private JRadioButton clothesNameRdBtn,serviceTypeRdBtn;
	private JButton searchBtn;
	
	private JButton addBtn,modifyBtn,deleteBtn,quitBtn;
	
	private String tableHeaders[] = { "衣服编号", "衣服名称", "服务类型", "单价", "最低折扣","操作员","添加日期" };
	private JTable clothesPricesSetTable;
	
	public ClothesPriceSetPanel(){
		this.setLayout(new BorderLayout());
		this.add(buildTopPanel(),BorderLayout.NORTH);
		this.add(buildScrollPane());
		initialize();
	}
	
	public void initialize(){
		ClothesTypeDao clothesTypeDao = new ClothesTypeDaoImpl();
		try{
			Vector clothesTypeVector = clothesTypeDao.getClothesType();
			DefaultTableModel tableModel = (DefaultTableModel)this.buildClothesTable().getModel();
			Iterator it = clothesTypeVector.iterator();
			while(it.hasNext()){
				ClothesTypeVo vo = (ClothesTypeVo)it.next();
				Object[] content = {Integer.toString(vo.getClothesId()),vo.getClothesName(),
						vo.getServiceType(),Double.toString(vo.getUnitOriginalPrice()),Double.toString(vo.getLowestDiscount()),
						vo.getOperatorName(),vo.getAddDate()};
				tableModel.addRow(content);	
			}
		}catch(DbException e){
			JOptionPane.showMessageDialog(null, e.getMessage());
		}
		
	}
	
	public JPanel buildTopPanel(){
		JPanel panel = new JPanel();
		panel.add(buildSearchPanel());
		panel.add(buildOperBtnPanel());
		return panel;
	}
	
	public JPanel buildSearchPanel(){
		JPanel panel = new JPanel();
		panel.add(buildlabelAndTxFldPanel());
		panel.add(buildRadioBtnPanel());
		panel.add(buildSearchBtn());
		return panel;
	}
	
	public JPanel buildlabelAndTxFldPanel(){
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(1,2));
		panel.add(new JLabel("搜素关键字:"));
		panel.add(buildKeywordTxFld());
		return panel;
	}
	
	public JTextField buildKeywordTxFld(){
		if(keywordTxFld == null){
			keywordTxFld = new JTextField();
		}
		return keywordTxFld;
	}
	
	public JPanel buildRadioBtnPanel(){
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(2,1));
		ButtonGroup group = new ButtonGroup();
		JRadioButton NameRdBtn = buildClothesNameRdBtn();
		JRadioButton TypeRdBtn = buildServiceTypeRdBtn();
		group.add(NameRdBtn);
		group.add(TypeRdBtn);
		panel.add(NameRdBtn);
		panel.add(TypeRdBtn);
		return panel;
	}
	
	public JRadioButton buildClothesNameRdBtn(){
		if(clothesNameRdBtn == null){
			clothesNameRdBtn = new JRadioButton("按衣服名称搜素");
		}
		return clothesNameRdBtn;
	}
	
	public JRadioButton buildServiceTypeRdBtn(){
		if(serviceTypeRdBtn == null){
			serviceTypeRdBtn = new JRadioButton("按服务类型搜素");
		}
		return serviceTypeRdBtn;
	}
	
	public JButton buildSearchBtn(){
		if(searchBtn == null){
			searchBtn = new JButton("搜素");
			searchBtn.setToolTipText("当按键字内容为空时,将搜索处所有衣服类型");
		}
		return searchBtn;
	}
	
	public JPanel buildOperBtnPanel(){
		JPanel panel = new JPanel();
		panel.add(buildAddBtn());
		panel.add(buildModifyBtn());
		panel.add(buildDeleteBtn());
		panel.add(buildQuitBtn());
		return panel;
	}
	public JButton buildAddBtn(){
		if(addBtn == null){
			addBtn = new JButton("添加"); 
		}
		return addBtn;
	}
	
	public JButton buildModifyBtn(){
		if(modifyBtn == null){
			modifyBtn = new JButton("修改"); 
		}
		return modifyBtn;
	}
	
	public JButton buildDeleteBtn(){
		if(deleteBtn == null){
			deleteBtn = new JButton("删除"); 
		}
		return deleteBtn;
	}
	
	public JButton buildQuitBtn(){
		if(quitBtn == null){
			quitBtn = new JButton("退出"); 
		}
		return quitBtn;
	}
	
	
	public JScrollPane buildScrollPane() {
		return new JScrollPane(
				buildClothesTable());
	}

	public JTable buildClothesTable() {
		if (clothesPricesSetTable == null) {
			Object[][] data = {};
			DefaultTableModel tableModel = new DefaultTableModel(data,
					tableHeaders) {
				public boolean isCellEditable(int rowIndex, int columnIndex) {
					return false;
				}
			};
			clothesPricesSetTable = new JTable(tableModel);
		}
		return clothesPricesSetTable;
	}
	
	public void setClothesTypeTable(Vector clothesTypeVector) {
		JTable table = this.buildClothesTable();
		int rowCount = table.getRowCount();
		DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
		while(rowCount > 0){
			tableModel.removeRow(0);
			rowCount--;
		}
		if(clothesTypeVector == null){
			return;
		}
		Iterator it = clothesTypeVector.iterator();
		while (it.hasNext()) {
			ClothesTypeVo vo = (ClothesTypeVo) it.next();
			Object[] content = {Integer.toString(vo.getClothesId()),vo.getClothesName(),
					vo.getServiceType(),Double.toString(vo.getUnitOriginalPrice()),Double.toString(vo.getLowestDiscount()),
					vo.getOperatorName(),vo.getAddDate()};
			tableModel.addRow(content);
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame f = new JFrame();
		f.add(new ClothesPriceSetPanel());
		f.pack();
		f.setSize(800,400);
		f.setVisible(true);
	}

}

⌨️ 快捷键说明

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