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

📄 cartbean.java

📁 基于netbeans的java桌面应用程序合集
💻 JAVA
字号:
/*
 * CartBean.java
 *
 * Created on 2008年1月30日, 上午7:46
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Adam;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 *
 * @author acer
 */
public class CartBean {
    private Hashtable hash=new Hashtable();
    /** Creates a new instance of CartBean */
    public CartBean() {
    }
    private void productNotExit(Vector vec,String id){
        Enumeration enume=vec.elements();
        int tempid=Integer.parseInt(id);
        while(enume.hasMoreElements()){
            ProductBean pb=(ProductBean)enume.nextElement();
            if(tempid==(pb.getProductId())){
                CartProduct cp=new CartProduct();
                cp.setProductId(pb.getProductId());
                cp.setProductName(pb.getProductName());
                cp.setSelectedCount(1);
                cp.setProductPrice(pb.getProductPrice());
                hash.put(id,cp);
                return;
            }
        }
    }
    public void addToCart(Vector vec,String id){
        if(hash.get(id)!=null){
            CartProduct tempcp=(CartProduct)hash.get(id);
            CartProduct cp=new CartProduct();
            cp.setProductId(tempcp.getProductId());
            cp.setProductName(tempcp.getProductName());
            cp.setSelectedCount(tempcp.getSelectedCount()+1);
            cp.setProductPrice(tempcp.getProductPrice());
            hash.remove(id);
            hash.put(id,cp);
        }else{
            this.productNotExit(vec,id);
        }
    }
    public Hashtable getCartContent(){
        return this.hash;
    }
    public void deleteFromCart(String id){
        this.hash.remove(id);
    }
    public void clearCart(){
        this.hash.clear();
    }
    public boolean isEmpty(){
        boolean empty=false;
        if(this.hash.isEmpty()){
            empty=true;
        }else{
            empty=false;
        }
        return empty;
    }
}

⌨️ 快捷键说明

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