📄 cartbean.java
字号:
package mybeans;
import java.util.ArrayList; // 要求JDK1.2以上
public class CartBean {
private String[] itemsSelected = null;
/*被选的商品*/
private String action = null;
/*进行的操作*/
private ArrayList itemsList = new ArrayList();
/*购物车的全部商品*/
public synchronized void setAction (String newAction) {
action = newAction;
if (action.startsWith("clear")) { //判断是否选择清空操作
itemsList.clear();//清空购物车
}
}
public synchronized void setItemsSelected (String[] newItems) {
if (newItems != null) { // some items selected
for (int i = 0; i < newItems.length; i++) {
if (action.startsWith("add")) { //加入到购物车中
itemsList.add(newItems[i]);
} else if (action.startsWith("move")) { //移出购物车
/*寻找最后一个所选择的商品,并移出购物车*/
int index = itemsList.lastIndexOf(newItems[i]);
if (index != -1) {
itemsList.remove(index);
}
}
}
}
}
public int countItems () {
return itemsList.size();
}
/*用来得到指定索引的商品*/
public Object getItem(int index)
{
return itemsList.get(index);
}
/*用来得到购物车的全部商品*/
public ArrayList getOrder()
{
return itemsList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -