购物车--郭雅芳、个人博客

1 团队课程设计博客链接

2 个人负责模块或任务说明

  • 管理员界面:管理数据库,可以进行添加、撤销添加、返回登录页面
  • 用户界面:商品信息下拉框(通过数据库读入商品信息,选中商品显示相应信息)、加入购物车将商品加入list并且显示在表格中(进行删除、清空、结算)

3 自己的代码提交记录截图

4 自己负责模块或任务详细说明

//   管理员界面:管理数据库,可以进行添加、撤销添加、返回登录页面 
//   用户界面:商品信息下拉框(通过数据库读入商品信息,选中商品显示相应信息)、加入购物车将商品加入list并且显示在表格中(进行删除、清空、结算)
管理界面:
     添加按键:
	private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
    try{
         conn=DriverManager.getConnection(url,userName,password);
         st = conn.createStatement();
		//通过sql语句,将文本框内的商品信息加入购物车,并且加入mlist。
         String sql="insert into goods(name,price,num,color,size)"
                 + " values('"+Text1.getText()+"',"+Double.parseDouble(Text2.getText())+","+Integer.parseInt(Text3.getText())+",'"+Text4.getText()+"','"+Text5.getText()+"')";
         st.executeUpdate(sql);
        }catch (SQLException e){
         e.printStackTrace();
         }
        mlist.add(new Clothes(Text1.getText(),Double.parseDouble(Text2.getText()),
    Integer.parseInt(Text3.getText()),Text4.getText(),Text5.getText()));
		//统计加入了多少条商品信息,显示到TextArea
        goodsNum++;
        addGoods();
}
  撤销添加:
private void cancleButtonActionPerformed(java.awt.event.ActionEvent evt) {   
        if(goodsNum>0){
           goodsNum--;
           try{
            conn=DriverManager.getConnection(url,userName,password);
             st = conn.createStatement();
             String delName=mlist.get(goodsNum).getName();
             String sql = "delete from goods where name = '"+delName+"' ";  
             System.out.println(sql);
             st.executeUpdate(sql); 
            }catch (SQLException e){
             e.printStackTrace();
             }
                 addGoods();
        }
}  

用户界面:
   组合框获取数据库中商品信息
private static void addComboxItem(){
    	try{ 
		conn=DriverManager.getConnection(url,userName,password);
         st = conn.createStatement();
         String sql="select * from goods";
         rs=st.executeQuery(sql);
         while(rs.next()){
             list.add(new Clothes(rs.getString("name"),rs.getDouble("price"),rs.getInt("num"),rs.getString("color"),rs.getString("size")));
         }
        }catch (SQLException e){
         e.printStackTrace();
         }
        System.out.println();
        for(int i=0;i<list.size();i++){ 
        	String a=list.get(i).getName();
			//addItem方法加入组合框列表中
        	clothesComboBox.addItem(a); 
        }
显示商品:
private void clothesComboBoxActionPerformed(java.awt.event.ActionEvent evt) 
{		//获得你选中的下拉框的位置
        int i=clothesComboBox.getSelectedIndex();
		//如何i大于零,则将信息显示购物车界面
         if(i>=0) {
            jLabel6.setText(list.get(i).getName());
            jLabel7.setText(Double.toString(list.get(i).getPrice()));
            jLabel8.setText(Integer.toString(list.get(i).getNum()));
            jLabel9.setText(list.get(i).getColor());
            jLabel10.setText(list.get(i).getSize());
         }
 }    
     加入购物车:      
private  void addButtonActionPerformed(java.awt.event.ActionEvent evt) 
{		//建立一个GoodDao table;
        GoodsDao goodDao = new Jtable(jTable1);
        try{
            count=Integer.parseInt(jTextField1.getText());
        }catch(NumberFormatException e){
            System.out.println(e);
        }
         int i=clothesComboBox.getSelectedIndex();
         if(i>=0) {
            String name=list.get(i).getName();
            double price=list.get(i).getPrice();
            Goods good = new Goods(name,price,count);
            boolean flag = goodDao.save(good);
            if(flag){
                JOptionPane.showMessageDialog(null, "添加成功");
            }else{
                JOptionPane.showMessageDialog(null, "添加失败!");
            }
            sum+=list.get(i).getPrice()*count;
         }
    }     

5 课程设计感想

  • 对图形界面的了解更深了一些,可以完成一个较简单的图形界面,但是对于相关模块的交互还不是很懂,有些代码不能及时更新信息。对于代码的修改有点盲目,没有弄清楚出错点。
posted @ 2017-06-22 15:33  _Another  阅读(204)  评论(0编辑  收藏  举报