在线购物商品分类jsp,java代码怎么写,有父类子类的?N种办法
1、mybatis配置文件 写SQL 解决
2、通过JAVA service 通过父类信息查询子类并封装
3、提供一个接口,前台二级联动方式 , 点第一个给后台传值0 ,查询父ID为0 的 当点击第二个联动的时候 把第一个信息的ID 给你传过去,如 电子数码ID 为1 那就传1后台还是根据父类查询,也就是 父类ID 1这样就查出 所对应的 子类信息了 。
你好,java购物车代码?import java.awt.*;
import java.awt.event.*;
class ShopFrame extends Frame implements ActionListener
{ Label label1,label2,label3,label4;
Button button1,button2,button3,button4,button5;
TextArea text;
Panel panel1,panel2;
static float sum=0.0f;
ShopFrame(String s)
{ super(s);
setLayout(new BorderLayout());
label1=new Label("面纸:3元",Label.LEFT);
label2=new Label("钢笔:5元",Label.LEFT);
label3=new Label("书:10元",Label.LEFT);
label4=new Label("袜子:8元",Label.LEFT);
button1=new Button("加入购物车");
button2=new Button("加入购物车");
button3=new Button("加入购物车");
button4=new Button("加入购物车");
button5=new Button("查看购物车");
text=new TextArea("商品有:" "\n",5,10);
text.setEditable(false);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
}
);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
panel1=new Panel();
panel2=new Panel();
panel1.add(label1);
panel1.add(button1);
panel1.add(label2);
panel1.add(button2);
panel1.add(label3);
panel1.add(button3);
panel1.add(label4);
panel1.add(button4);
panel2.setLayout(new BorderLayout());
panel2.add(button5,BorderLayout.NORTH);
panel2.add(text,BorderLayout.SOUTH);
this.add(panel1,BorderLayout.CENTER);
this.add(panel2,BorderLayout.SOUTH);
setBounds(100,100,350,250);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==button1)
{ text.append("一个面纸、");
sum=sum 3;
}
else if(e.getSource()==button2)
{ text.append("一只钢笔、");
sum=sum 5;
}
else if(e.getSource()==button3)
{ text.append("一本书、");
sum=sum 10;
}
else if(e.getSource()==button4)
{ text.append("一双袜子、");
sum=sum 8;
}
else if(e.getSource()==button5)
{
text.append("\n" "总价为:" "\n" sum);
}
}
}
public class Shopping {
public static void main(String[] args) {
new ShopFrame("购物车");
}
}
我没用Swing可能显示不出来购物商店java代码你的效果 。不满意得话我在给购物商店java代码你编一个 。
求一套完整的JAVA WEB项目的网络购物网站源代码/**
* @description:
* @author chenshiqiang E-mail:csqwyyx@163.com
* @date 2014年9月7日 下午2:51:50
* @version 1.0
*/
package com.example.baidumap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ListView;
import com.baidu.mapapi.map.offline.MKOLSearchRecord;
import com.baidu.mapapi.map.offline.MKOLUpdateElement;
import com.baidu.mapapi.map.offline.MKOfflineMap;
import com.baidu.mapapi.map.offline.MKOfflineMapListener;
import com.example.baidumap.adapters.OfflineExpandableListAdapter;
import com.example.baidumap.adapters.OfflineMapAdapter;
import com.example.baidumap.adapters.OfflineMapManagerAdapter;
import com.example.baidumap.interfaces.OnOfflineItemStatusChangeListener;
import com.example.baidumap.models.OfflineMapItem;
import com.example.baidumap.utils.CsqBackgroundTask;
import com.example.baidumap.utils.ToastUtil;
import com.example.system.R;
public class BaiduOfflineMapActivity extends Activity implements MKOfflineMapListener, OnOfflineItemStatusChangeListener
{
// ------------------------ Constants ------------------------
// ------------------------- Fields --------------------------
private ViewPager viewpager;
private PagerTabStrip pagertab;
private MySearchView svDown;
private ListView lvDown;
private MySearchView svAll;
private ExpandableListView lvWholeCountry;
private ListView lvSearchResult;
private ListView views = new ArrayListView(2);
private ListString titles = new ArrayListString(2);
private MKOfflineMap mOffline = null;
private OfflineMapManagerAdapter downAdapter;
private OfflineMapAdapter allSearchAdapter;
private OfflineExpandableListAdapter allCountryAdapter;
private ListOfflineMapItem itemsDown; // 下载或下载中城市
private ListOfflineMapItem itemsAll; // 所有城市,与热门城市及下载管理对象相同
private ListOfflineMapItem itemsProvince;
private ListListOfflineMapItem itemsProvinceCity;
// ----------------------- Constructors ----------------------
// -------- Methods for/from SuperClass/Interfaces -----------
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offline_map);
//final String packname = this.getPackageName();
//PackageInfo packageInfo;
//try
//{
//packageInfo = this.getPackageManager().getPackageInfo(packname, PackageManager.GET_SIGNATURES);
//
//
//if (code == -00)
//{
// 初始化离线地图管理
mOffline = new MKOfflineMap();
mOffline.init(this);
initViews();
viewpager.setCurrentItem(1);
//}
//}
//catch (NameNotFoundException e)
//{
//e.printStackTrace();
//}
}
private boolean isResumed = false;
@Override
protected void onResume()
{
super.onResume();
if (!isResumed)
{
isResumed = true;
loadData();
}
}
@Override
protected void onDestroy()
{
super.onDestroy();
mOffline.destroy();
【购物商店java代码 java超市购物代码】 }
/**
*
* @author chenshiqiang E-mail:csqwyyx@163.com
* @param type
*事件类型: MKOfflineMap.TYPE_NEW_OFFLINE, MKOfflineMap.TYPE_DOWNLOAD_UPDATE, MKOfflineMap.TYPE_VER_UPDATE.
* @param state
*事件状态: 当type为TYPE_NEW_OFFLINE时,表示新安装的离线地图数目. 当type为TYPE_DOWNLOAD_UPDATE时,表示更新的城市ID.
*/
@Override
public void onGetOfflineMapState(int type, int state)
{
switch (type)
{
case MKOfflineMap.TYPE_DOWNLOAD_UPDATE:
MKOLUpdateElement update = mOffline.getUpdateInfo(state);
if (setElement(update, true) != null)
{
if (itemsDown != nullitemsDown.size()1)
{
Collections.sort(itemsDown);
}
refreshDownList();
}
else
{
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
break;
case MKOfflineMap.TYPE_NEW_OFFLINE:
// 有新离线地图安装
Log.d("OfflineDemo", String.format("add offlinemap num:%d", state));
break;
case MKOfflineMap.TYPE_VER_UPDATE:
// 版本更新提示
break;
}
}
/**
* 百度下载状态改变(暂停--》恢复)居然不回调,所以改变状态时自己得增加接口监听状态改变刷新界面
*
* @author chenshiqiang E-mail:csqwyyx@163.com
* @param item
*有状态改变的item
* @param removed
*item是否被删除
*/
@Override
public void statusChanged(OfflineMapItem item, boolean removed)
{
if (removed)
{
for (int i = itemsDown.size() - 1; i = 0; i--)
{
OfflineMapItem temp = itemsDown.get(i);
if (temp.getCityId() == item.getCityId())
{
itemsDown.remove(i);
}
}
refreshDownList();
}
else
{
loadData();
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
}
// --------------------- Methods public ----------------------
public void toDownloadPage()
{
viewpager.setCurrentItem(0);
}
// --------------------- Methods private ---------------------
private void initViews()
{
// TODO
viewpager = (ViewPager) findViewById(R.id.viewpager);
pagertab = (PagerTabStrip) findViewById(R.id.pagertab);
LayoutInflater inf = LayoutInflater.from(this);
View v1 = inf.inflate(R.layout.view_offline_download, null, false);
svDown = (MySearchView) v1.findViewById(R.id.svDown);
lvDown = (ListView) v1.findViewById(R.id.lvDown);
views.add(v1);
View v2 = inf.inflate(R.layout.view_offline_countrys, null, false);
svAll = (MySearchView) v2.findViewById(R.id.svAll);
lvWholeCountry = (ExpandableListView) v2.findViewById(R.id.lvWholeCountry);
lvSearchResult = (ListView) v2.findViewById(R.id.lvSearchResult);
views.add(v2);
titles.add("下载管理");
titles.add("城市列表");
pagertab.setTabIndicatorColor(0xff00cccc);
pagertab.setDrawFullUnderline(false);
pagertab.setBackgroundColor(0xFF38B0DE);
pagertab.setTextSpacing(50);
viewpager.setOffscreenPageLimit(2);
viewpager.setAdapter(new MyPagerAdapter());
svDown.setSearchListener(new MySearchView.SearchListener()
{
@Override
public void afterTextChanged(Editable text)
{
refreshDownList();
}
@Override
public void search(String text)
{
}
});
svAll.setSearchListener(new MySearchView.SearchListener()
{
@Override
public void afterTextChanged(Editable text)
{
refreshAllSearchList();
}
@Override
public void search(String text)
{
}
});
downAdapter = new OfflineMapManagerAdapter(this, mOffline, this);
lvDown.setAdapter(downAdapter);
allSearchAdapter = new OfflineMapAdapter(this, mOffline, this);
lvSearchResult.setAdapter(allSearchAdapter);
allCountryAdapter = new OfflineExpandableListAdapter(this, mOffline, this);
lvWholeCountry.setAdapter(allCountryAdapter);
lvWholeCountry.setGroupIndicator(null);
}
/**
* 刷新下载列表, 根据搜索关键字及itemsDown 下载管理数量变动时调用
*/
private void refreshDownList()
{
String key = svDown.getInputText();
if (key == null || key.length()1)
{
downAdapter.setDatas(itemsDown);
}
else
{
ListOfflineMapItem filterList = new ArrayListOfflineMapItem();
if (itemsDown != null!itemsDown.isEmpty())
{
for (OfflineMapItem i : itemsDown)
{
if (i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
downAdapter.setDatas(filterList);
}
}
/**
* 刷新所有城市搜索结果
*/
private void refreshAllSearchList()
{
String key = svAll.getInputText();
if (key == null || key.length()1)
{
lvSearchResult.setVisibility(View.GONE);
lvWholeCountry.setVisibility(View.VISIBLE);
allSearchAdapter.setDatas(null);
}
else
{
lvSearchResult.setVisibility(View.VISIBLE);
lvWholeCountry.setVisibility(View.GONE);
ListOfflineMapItem filterList = new ArrayListOfflineMapItem();
if (itemsAll != null!itemsAll.isEmpty())
{
for (OfflineMapItem i : itemsAll)
{
if (i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
allSearchAdapter.setDatas(filterList);
}
}
private void loadData()
{
new CsqBackgroundTaskVoid(this)
{
@Override
protected Void onRun()
{
// TODO Auto-generated method stub
// 导入离线地图包
// 将从官网下载的离线包解压,把vmp文件夹拷入SD卡根目录下的BaiduMapSdk文件夹内 。
// 把网站上下载的文件解压,将\BaiduMap\vmp\l里面的.dat_svc文件,拷贝到手机BaiduMapSDK/vmp/h目录下
int num = mOffline.importOfflineData();
if (num0)
{
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this, "成功导入"num"个离线包", false);
}
ListMKOLSearchRecord all = null;
try
{
all = mOffline.getOfflineCityList();
}
catch (Exception e)
{
e.printStackTrace();
}
if (all == null || all.isEmpty())
{
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this, "未获取到离线地图城市数据,可能有其他应用正在使用百度离线地图功能!", false);
return null;
}
ListMKOLSearchRecord hotCity = mOffline.getHotCityList();
HashSetInteger hotCityIds = new HashSetInteger();
if (!hotCity.isEmpty())
{
for (MKOLSearchRecord r : hotCity)
{
hotCityIds.add(r.cityID);
}
}
itemsAll = new ArrayListOfflineMapItem();
itemsDown = new ArrayListOfflineMapItem();
itemsProvince = new ArrayListOfflineMapItem();
itemsProvinceCity = new ArrayListListOfflineMapItem();
// cityType 0:全国;1:省份;2:城市,如果是省份,可以通过childCities得到子城市列表
// 全国概略图、直辖市、港澳 子城市列表
ArrayListMKOLSearchRecord childMunicipalities = new ArrayListMKOLSearchRecord();
proHot.cityName = "热门城市";
proHot.childCities = cs;
ListMKOLUpdateElement updates = mOffline.getAllUpdateInfo();
if (updates != nullupdates.size()0)
{
}
@Override
protected void onResult(Void result)
{
// TODO Auto-generated method stub
refreshDownList();
refreshAllSearchList();
allCountryAdapter.setDatas(itemsProvince, itemsProvinceCity);
}
}.execute();
}
急求java购物车代码package bean;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Administrator
* 购物车类:
* 为了方便将商品信息绑订到session上面而设计的一个
* 工具,提供了商品的添加,删除 , 列表,计价,清空 ,
* 修改功能 。
*/
public class Cart {
//items属性:用来保存商品
private ListCartItem items =
new ArrayListCartItem();
/**
* 将商品添加到购物车
*/
public boolean add(CartItem item){
for(int i=0;iitems.size();i){
CartItem curr = items.get(i);
if(curr.getC().getId() == item.getC().getId()){
//该商品已经购买过
return false;
}
}
//没有购买过 , 则添加该商品
items.add(item);
return true;
}
/**
* 从购物车当中删除某件商品
*/
public void delete(int id){
for(int i=0;iitems.size();i){
CartItem curr = items.get(i);
if(curr.getC().getId() == id){
items.remove(curr);
return;
}
}
}
/**
* 获得购物车中所有商品信息
*/
public ListCartItem list(){
return items;
}
/**
* 商品总价
*/
public double cost(){
double total = 0;
for(int i=0;iitems.size();i){
CartItem curr = items.get(i);
total= curr.getC().getPrice() * curr.getQty();
}
return total;
}
/**
* 清空购物车中的所有商品
*/
public void clear(){
items.clear();
}
/**
* 修改购物车中某种商品的数量
*/
public void modify(int id,int qty){
for(int i=0;iitems.size();i){
CartItem curr = items.get(i);
if(curr.getC().getId() == id){
curr.setQty(qty);
return;
}
}
}
}
java简单的购物车代码package Test;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
init();//初始化
MapString,String map = new LinkedHashMap();
while(true){
Scanner in= new Scanner(System.in);
map = buy(in,map);//选择
System.out.println();
System.out.println("还要继续购物吗?(Y/N)");
String jx = in.nextLine();
if(jx.equals("N")){
break;
}
}
print(map);
}
public static void print(MapString, String m){
System.out.println("\n\n\n******************");
System.out.println("购物车清单");
Integer hj = 0;
for (EntryString, String entry : m.entrySet()) {
String key = entry.getKey();
String value = https://www.04ip.com/post/entry.getValue();
if(key.equals("1")){
hj= Integer.parseInt(value)*3;
System.out.println("哇哈哈纯净水: " value "件 , 合计:¥" Integer.parseInt(value)*3);
}else if(key.equals("2")){
hj= Integer.parseInt(value)*5;
System.out.println("康师傅方便面: " value "件,合计:¥" Integer.parseInt(value)*5);
}else if(key.equals("3")){
hj= Integer.parseInt(value)*4;
System.out.println("可口可乐: " value "件,合计:¥" Integer.parseInt(value)*4);
}
}
System.out.println("合计金额:¥" hj);
}
public static void init(){
System.out.println("******************");
System.out.println("\t商品列表\n");
System.out.println("商品名称价格");
System.out.println("1.哇哈哈纯净水¥3");
System.out.println("2.康师傅方便面¥5");
System.out.println("3.可口可乐¥4");
System.out.println("******************");
}
public static MapString,String buy(Scanner scan,MapString,String m){
System.out.print("请输入编号:");
String bh = scan.nextLine();
System.out.print("请输入购买数量:");
String num = scan.nextLine();
if(m.size()0m.keySet().contains(bh)){
m.put(bh,(Integer.parseInt(bh) Integer.parseInt(num)) "");
}else{
m.put(bh, num);
}
return m;
}
}
关于购物商店java代码和java超市购物代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 好看的小程序商城运营方案,小程序商业运营方案
- 如何复制图片到word,如何复制图片到excel表格
- 软件技术的学生毕业设计,软件专业的毕业设计
- 猎罪图鉴java代码 猎罪图鉴豆瓣
- redis设置为开机启动不了,redis开机自启动设置
- 3d汽车游戏单机版,3d汽车游戏单机版大全
- cpu4核显卡有什么用,四核显卡是什么意思
- vb.net日期相加 vbs日期加减
- html5仿微信朋友圈,朋友圈 html