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

📄 addnewclothestypepanel.java

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

import java.awt.BorderLayout;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import view.frame.MainFrame;
import view.panel.basePanel.ClothesTypeInfoPanel;
import vo.ClothesTypeVo;

public class AddNewClothesTypePanel extends JPanel {
	private ClothesTypeInfoPanel clothesTypeInfoPanel;
	private JButton addBtn, clearBtn, quitBtn;

	public AddNewClothesTypePanel() {
		this.setLayout(new BorderLayout());
		this.add(buildClothesTypeInfoPanel());
		this.add(buildOperBtnPanel(), BorderLayout.SOUTH);
	}

	public ClothesTypeInfoPanel buildClothesTypeInfoPanel() {
		if (clothesTypeInfoPanel == null) {
			clothesTypeInfoPanel = new ClothesTypeInfoPanel();
		}
		return clothesTypeInfoPanel;
	}

	public JPanel buildOperBtnPanel() {
		JPanel panel = new JPanel();
		panel.add(buildAddBtn());
		panel.add(buildClearBtn());
		panel.add(buildQuitBtn());
		return panel;
	}

	public JButton buildAddBtn() {
		if (addBtn == null) {
			addBtn = new JButton("添加");
		}
		return addBtn;
	}

	public JButton buildClearBtn() {
		if (clearBtn == null) {
			clearBtn = new JButton("清空");
		}
		return clearBtn;
	}

	public JButton buildQuitBtn() {
		if (quitBtn == null) {
			quitBtn = new JButton("退出");
		}
		return quitBtn;
	}

	public ClothesTypeVo getClothesTypeVo() throws NumberFormatException {
		int clothesId = Integer.parseInt(clothesTypeInfoPanel
				.buildClothesIdTxFld().getText());
		String clothesName = clothesTypeInfoPanel.buildClothesTypeTxFld()
				.getText();
		String serviceType = clothesTypeInfoPanel.buildServiceTypeTxFld()
				.getText();
		if (clothesName.equals("")) {
			JOptionPane.showMessageDialog(null, "您还没输入衣服名称");
			return null;
		}
		if (serviceType.equals("")) {
			JOptionPane.showMessageDialog(null, "您还没输入服务类型");
			return null;
		}
		double unitOriginalPrice = Double.parseDouble(clothesTypeInfoPanel
				.buildPriceTxFld().getText());
		if (unitOriginalPrice >= 100 || unitOriginalPrice <= 0) {
			JOptionPane.showMessageDialog(null, "单价必须大于0,小于100,谢谢");
			return null;
		}
		if (unitOriginalPrice != new Double(unitOriginalPrice).intValue()) {
				JOptionPane.showMessageDialog(null, "输入的衣服单价只能为整数,谢谢");
				return null;
		}
		double lowestDiscount = Double.parseDouble(clothesTypeInfoPanel
				.buildDiscountTxFld().getText());
		if (lowestDiscount < 0 || lowestDiscount > 10) {
			JOptionPane.showMessageDialog(null, "折扣必须在0和10之间,谢谢");
			return null;
		}
		if (lowestDiscount != new Double(lowestDiscount).intValue()) {
			int decimalLen = (lowestDiscount+"").length() - (lowestDiscount+"").indexOf(".")-1;
			if(decimalLen >= 2){
				JOptionPane.showMessageDialog(null, "小数最多能有一位,谢谢");
				return null;
			}
			/*DecimalFormat format = new DecimalFormat("#0.0");
			lowestDiscount = Double
					.parseDouble(format.format(clothesTypeInfoPanel
							.buildDiscountTxFld().getText()));*/
		}
		String operatorName = MainFrame.getOperatorName();
		SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy'-'MM'-'dd");
		String addDate = dataFormat.format(new Date());
		return new ClothesTypeVo(clothesId, clothesName, serviceType,
				unitOriginalPrice, lowestDiscount, operatorName, addDate);
	}

	public void clearContent() {
		clothesTypeInfoPanel.buildClothesIdTxFld().setText("");
		clothesTypeInfoPanel.buildClothesTypeTxFld().setText("");
		clothesTypeInfoPanel.buildServiceTypeTxFld().setText("");
		clothesTypeInfoPanel.buildPriceTxFld().setText("");
		clothesTypeInfoPanel.buildDiscountTxFld().setText("");
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame f = new JFrame();
		f.add(new AddNewClothesTypePanel());
		f.pack();
		f.setSize(500, 400);
		f.setVisible(true);
	}

}

⌨️ 快捷键说明

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