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

📄 editonegoods.java

📁 基于 C/S 模式的网上购物系统
💻 JAVA
字号:
package RegisterAndLogin;

import java.awt.BorderLayout;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.lang.Integer;
import javax.swing.JOptionPane;
public class EditOneGoods extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	public ShopHostUI parent=null;
    public Socket clientSocket=null;	   
 	public  ObjectOutputStream os=null;
 	public ObjectInputStream is=null;
 	public int row=0;

	private JLabel jLabelGoodsId = null;

	private JTextField jTextFieldGoodsId = null;

	private JLabel jLabelGoodsName = null;

	private JTextField jTextFieldGoodsName = null;

	private JLabel jLabelPrice = null;

	private JTextField jTextFieldPrice = null;

	private JLabel jLabelProduceArea = null;

	private JTextField jTextFieldProduceArea = null;

	private JLabel jLabelAmount = null;

	private JTextField jTextFieldAmount = null;

	private JLabel jLabelUnit = null;

	private JTextField jTextFieldUnit = null;

	private JLabel jLabelIntroduce = null;

	private JTextArea jTextAreaIntroduce = null;

	private JButton jButtonSubmit = null;

	private JButton jButtonCancle = null;
	public merchandise goods=new merchandise();
	/**
	 * This is the default constructor
	 */
	public EditOneGoods(ShopHostUI parent,Socket clientSocket,ObjectOutputStream os,ObjectInputStream is,int row,merchandise goods) {
		super();
		this.parent=parent;
		this.clientSocket=clientSocket;
		this.os=os;
		this.is=is;
		this.row=row;
		this.goods=goods;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(328, 460);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
		this.setVisible(true);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabelIntroduce = new JLabel();
			jLabelIntroduce.setBounds(new Rectangle(23, 277, 97, 29));
			jLabelIntroduce.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelIntroduce.setText("商品简介");
			jLabelUnit = new JLabel();
			jLabelUnit.setBounds(new Rectangle(15, 230, 104, 29));
			jLabelUnit.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelUnit.setText("单位");
			jLabelAmount = new JLabel();
			jLabelAmount.setBounds(new Rectangle(14, 185, 107, 33));
			jLabelAmount.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelAmount.setText("数量");
			jLabelProduceArea = new JLabel();
			jLabelProduceArea.setBounds(new Rectangle(11, 143, 109, 34));
			jLabelProduceArea.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelProduceArea.setText("产地");
			jLabelPrice = new JLabel();
			jLabelPrice.setBounds(new Rectangle(12, 101, 103, 28));
			jLabelPrice.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelPrice.setText("价格");
			jLabelGoodsName = new JLabel();
			jLabelGoodsName.setBounds(new Rectangle(8, 58, 105, 25));
			jLabelGoodsName.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelGoodsName.setText("商品名称");
			jLabelGoodsId = new JLabel();
			jLabelGoodsId.setBounds(new Rectangle(7, 16, 105, 28));
			jLabelGoodsId.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelGoodsId.setText("商品ID ");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabelGoodsId, null);
			jContentPane.add(getJTextFieldGoodsId(), null);
			jContentPane.add(jLabelGoodsName, null);
			jContentPane.add(getJTextFieldGoodsName(), null);
			jContentPane.add(jLabelPrice, null);
			jContentPane.add(getJTextFieldPrice(), null);
			jContentPane.add(jLabelProduceArea, null);
			jContentPane.add(getJTextFieldProduceArea(), null);
			jContentPane.add(jLabelAmount, null);
			jContentPane.add(getJTextFieldAmount(), null);
			jContentPane.add(jLabelUnit, null);
			jContentPane.add(getJTextFieldUnit(), null);
			jContentPane.add(jLabelIntroduce, null);
			jContentPane.add(getJTextAreaIntroduce(), null);
			jContentPane.add(getJButtonSubmit(), null);
			jContentPane.add(getJButtonCancle(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jTextFieldGoodsId	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldGoodsId() {
		if (jTextFieldGoodsId == null) {
			jTextFieldGoodsId = new JTextField();
			jTextFieldGoodsId.setBounds(new Rectangle(132, 18, 119, 27));
			jTextFieldGoodsId.setEditable(false);
			Integer  goodsid=goods.getgoodsId();
			jTextFieldGoodsId.setText(goodsid.toString());
		}
		return jTextFieldGoodsId;
	}

	/**
	 * This method initializes jTextFieldGoodsName	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldGoodsName() {
		if (jTextFieldGoodsName == null) {
			jTextFieldGoodsName = new JTextField();
			jTextFieldGoodsName.setBounds(new Rectangle(132, 54, 121, 30));
			jTextFieldGoodsName.setEditable(false);
			jTextFieldGoodsName.setText(goods.getgoodsName());
		}
		return jTextFieldGoodsName;
	}

	/**
	 * This method initializes jTextFieldPrice	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldPrice() {
		if (jTextFieldPrice == null) {
			jTextFieldPrice = new JTextField();
			jTextFieldPrice.setBounds(new Rectangle(134, 100, 122, 34));
		    Float price=goods.getPrice();
		    jTextFieldPrice.setText(price.toString());
		}
		return jTextFieldPrice;
	}

	/**
	 * This method initializes jTextFieldProduceArea	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldProduceArea() {
		if (jTextFieldProduceArea == null) {
			jTextFieldProduceArea = new JTextField();
			jTextFieldProduceArea.setBounds(new Rectangle(132, 146, 122, 34));
		    jTextFieldProduceArea.setText(goods.getProduceArea());
		}
		return jTextFieldProduceArea;
	}

	/**
	 * This method initializes jTextFieldAmount	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldAmount() {
		if (jTextFieldAmount == null) {
			jTextFieldAmount = new JTextField();
			jTextFieldAmount.setBounds(new Rectangle(130, 186, 129, 32));
		    Integer amount=goods.getAmount();
		    jTextFieldAmount.setText(amount.toString());
		}
		return jTextFieldAmount;
	}

	/**
	 * This method initializes jTextFieldUnit	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldUnit() {
		if (jTextFieldUnit == null) {
			jTextFieldUnit = new JTextField();
			jTextFieldUnit.setBounds(new Rectangle(131, 228, 129, 27));
		    jTextFieldUnit.setText(goods.getUnit());
		}
		return jTextFieldUnit;
	}

	/**
	 * This method initializes jTextAreaIntroduce	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextAreaIntroduce() {
		if (jTextAreaIntroduce == null) {
			jTextAreaIntroduce = new JTextArea();
			jTextAreaIntroduce.setBounds(new Rectangle(132, 272, 153, 98));
		    jTextAreaIntroduce.setText(goods.getIntroduce());
		}
		return jTextAreaIntroduce;
	}

	/**
	 * This method initializes jButtonSubmit	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSubmit() {
		if (jButtonSubmit == null) {
			jButtonSubmit = new JButton();
			jButtonSubmit.setBounds(new Rectangle(19, 384, 103, 30));
			jButtonSubmit.setText("确定");
			jButtonSubmit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				    try{
				    	String Msg=ConstanValue.MSG_UPDATE_INFO_OF_ONEGOODS;
				    	
						String price=jTextFieldPrice.getText().trim();
						String produceArea=jTextFieldProduceArea.getText().trim();
						String amount=jTextFieldAmount.getText().trim();
						String unit=jTextFieldUnit.getText().trim();
						String introduce=jTextAreaIntroduce.getText();
						float Price=Float.parseFloat(price);
						int Amount=Integer.parseInt(amount);
						os.writeObject(Msg);
						os.writeInt(goods.getgoodsId());
						os.writeObject(goods.getgoodsName());
						os.writeFloat(Price);
						os.writeObject(produceArea);
						os.writeObject(introduce);
						os.writeInt(Amount);
						os.writeObject(unit);
						os.flush();
						Msg=(String)is.readObject();
						if(Msg.equals(ConstanValue.MSG_ACC_UPDATE_INFO_OF_ONEGOODS))
						{
							JOptionPane.showMessageDialog(null, Msg);
							parent.jTableGoodsList.setValueAt(Price, row,3);
							parent.jTableGoodsList.setValueAt(produceArea, row,4);
							parent.jTableGoodsList.setValueAt(introduce, row,5);
							parent.jTableGoodsList.setValueAt(Amount, row,6);
							parent.jTableGoodsList.setValueAt(unit, row,7);
							setVisible(false);
						}
				    }
				    catch(Exception ex)
				    {
				    	ex.printStackTrace();
				    }
				}
			});
		}
		return jButtonSubmit;
	}

	/**
	 * This method initializes jButtonCancle	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancle() {
		if (jButtonCancle == null) {
			jButtonCancle = new JButton();
			jButtonCancle.setBounds(new Rectangle(156, 384, 117, 35));
			jButtonCancle.setText("取消");
		}
		return jButtonCancle;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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