找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2920|回復(fù): 0
收起左側(cè)

Java薯片購物管理系統(tǒng)的設(shè)計與實現(xiàn) 課程設(shè)計論文下載

[復(fù)制鏈接]
ID:171288 發(fā)表于 2017-3-16 17:43 | 顯示全部樓層 |閱讀模式

這是
大學(xué)實訓(xùn)的內(nèi)容,完整的java程序。

完整的論文下載(可編輯):
java.docx (711.08 KB, 下載次數(shù): 12)

下面是本設(shè)計的部分內(nèi)容預(yù)覽:
大連科技學(xué)院
Java程序設(shè)計課程設(shè)計(B)

題  目基于Java的薯片購物管理系統(tǒng)的設(shè)計與實現(xiàn)

學(xué)生姓名專業(yè)班級

指導(dǎo)教師   樊曉勇  職    稱   副教授      

所在單位   信息科學(xué)學(xué)院物聯(lián)網(wǎng)工程教研室      

教研室主任           孫 琦               


完成日期  2017 年1月 6 日


課程設(shè)計評分標準
項目
評價
成績
出勤與工作態(tài)度(20分)
A:沒有缺勤,工作態(tài)度積極主動B:缺勤一次,工作態(tài)度良好
C:缺勤二次,工作態(tài)度較好D:缺勤二次,工作態(tài)度較差
E:出勤狀況與工作態(tài)度差


功能、界面與數(shù)據(jù)庫設(shè)計(20分)
A:功能完善,數(shù)據(jù)庫設(shè)計規(guī)范     B:功能完整,數(shù)據(jù)庫設(shè)計規(guī)范
C:功能完整,數(shù)據(jù)庫設(shè)計較規(guī)范   D:功能較完整,數(shù)據(jù)庫設(shè)計較規(guī)范
E:功能與數(shù)據(jù)庫設(shè)計不完整


源代碼與程序運行(20分)
A:代碼正確,程序運行順利B:代碼完整,程序運行基本正常
C:代碼完整,程序運行有一處錯誤 D:代碼較完整,程序運行有二處錯誤
E:代碼不完整,程序運行有多處錯誤


設(shè)計報告結(jié)構(gòu)與內(nèi)容
(20分)
A:結(jié)構(gòu)清晰,內(nèi)容充實B:結(jié)構(gòu)完整,內(nèi)容較充實
C:結(jié)構(gòu)與內(nèi)容完整D:結(jié)構(gòu)與內(nèi)容較完整
E:結(jié)構(gòu)混亂,內(nèi)容欠缺


設(shè)計報告段落與圖表格式(20分)
A:段落規(guī)范,圖表規(guī)范正確B:段落規(guī)范,圖表有一處錯誤
C:段落較規(guī)范,圖表有二處錯誤D:段落完整,圖表有多處錯誤
E:段落不完整,圖表錯誤



項目成績評定標準:
A:成績給定17-20分,B:成績給定13-16分,C:成績給定9-12分,D:成績給定5-8,
E:成績給定0-4分。




綜 合  評 定:



(優(yōu)、良、中、及格、不及格)
































指導(dǎo)教師簽字:





2017年1月6日









目  錄

1薯片購物系統(tǒng)概述              1

1.1              系統(tǒng)簡介

1.2 系統(tǒng)開發(fā)所采用的技術(shù)

2數(shù)據(jù)庫結(jié)構(gòu)

2.1用戶表

2.2商品表

2.3訂單表

2.4購物車表

3 實體類定義

3.1User.java

3.1Goods.java

3.3Shop.java

4 功能類定義——圖形界面實現(xiàn)

4.1登錄界面

4.2 商品信息維護界面

4.3主頁面

4.4 商品購買頁面

4.5 單筆訂單支付界面

4.6 多筆訂單支付界面

4.7購物車維護界面

4.8購物信息修改界面界面

4.9 充值界面界面

5 功能類定義——數(shù)據(jù)庫操作實現(xiàn)

6 總結(jié)






1





1薯片購物系統(tǒng)概述1.1     系統(tǒng)簡介
購物模擬系統(tǒng)采用Java程序設(shè)計語言實現(xiàn)C/S模式下的電子商務(wù)模擬購物流程。模擬系統(tǒng)分前臺購物業(yè)務(wù)和后臺商品管理兩部分。
  • 前臺購物管理
前臺購物管理含有登錄、商品查詢、購買、將商品添加到購物車、下訂單、支付、查看購物車、查看訂單、批量支付、購物車維護(刪除、修改)、訂單維護(刪除)等功能。實現(xiàn)了電子商務(wù)中購買商品的整個業(yè)務(wù)流程。該部分功能的使用權(quán)限歸普通用戶。
  • 后臺商品管理
后臺管理的使用權(quán)限是管理員,管理員可實現(xiàn)對商品信息的維護(增、刪、改、查)。
1.2 系統(tǒng)開發(fā)所采用的技術(shù)
Eclipse是著名的跨平臺的自由集成開發(fā)環(huán)境,是一個開放源代碼、基于Java的可擴展開發(fā)平臺。就其本身而言,它只是一個框架和一組服務(wù),用于通過插件組件構(gòu)建開發(fā)環(huán)境。Eclipse附帶了一個標準的插件集,包括Java開發(fā)工具。
MySQL是一種開放源代碼的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),MySQL數(shù)據(jù)庫系統(tǒng)使用最常用的數(shù)據(jù)庫管理語言—結(jié)構(gòu)化查詢語言(SQL)進行數(shù)據(jù)庫管理。
Java是一種可以撰寫跨平臺應(yīng)用程序的面向?qū)ο蟮某绦蛟O(shè)計語言。Java技術(shù)具有卓越的通用性、高效性、平臺移植性和安全性,廣泛應(yīng)用于PC、數(shù)據(jù)中心、游戲控制臺、科學(xué)超級計算機、移動電話和互聯(lián)網(wǎng),同時擁有全球最大的開發(fā)者專業(yè)社群。
JDBC是一種用于執(zhí)行SQL語句的JavaAPI,可以為多種關(guān)系數(shù)據(jù)庫提供統(tǒng)一訪問,它由一組用Java語言編寫的類和接口組成。
1





2數(shù)據(jù)庫結(jié)構(gòu)2.1用戶表
字段名(列名)
中文描述
數(shù)據(jù)類型
約束
描述
userName
用戶名
varchar(20)
非空,主鍵
用戶登錄時使用的用戶名
password
密碼
char(10)
非空
登錄密碼
account
賬戶余額
double
默認值為0
用于支付、購買商品
identity
用戶身份
Int
非空
管理員1,普通用戶0

2.2商品表
字段名(列名)
中文描述
數(shù)據(jù)類型
約束
描述
goodsID
商品編號
char(5)
主鍵、非空
與顏色、尺寸共同形成主鍵
goodsName
商品名
varchar(20)
非空
商品名字
store
庫存量
int
非空
商品庫存數(shù)量,庫存量<=0不能上架
price
價格
double
非空
商品單價
color
顏色名
char(4)
非空
取值范圍白、紅、黃、米白
size
尺寸名
char(4)
非空
取值范圍S,M,X,XXL
image
商品圖片
varchar(50)
非空
商品圖片地址
detail
商品描述
varchar(50)
非空
商品詳細描述,特點等

2.3訂單表
字段名(列名)
中文描述
數(shù)據(jù)類型
約束
描述
orderID
訂單編號
char(5)
主鍵、非空
主鍵
goodsID
商品編號
char(5)
主鍵、非空
主鍵
goodsName
商品名
varchar(20)
非空
商品名字
orderTime
訂單日期
char(10)
主鍵、非空
主鍵
userName
用戶名
varchar(20)
主鍵、非空
主鍵
number
購買數(shù)量
int
非空
某種商品的購買數(shù)量
color
商品顏色
char(4)
非空
取值范圍白、紅、黃、米白
size
商品尺寸
char(4)
非空
取值范圍S,M,X,XXL
pay
支付狀態(tài)
boolean
非空
已支付該項為“true”,未支付為“false”
price
價格
double
非空
商品單價
2.4購物車表
字段名(列名)
中文描述
數(shù)據(jù)類型
約束
描述
goodsID
商品編號
char(10)
主鍵、非空
主鍵
goodsName
商品名
varchar(20)
非空
商品名字
userName
用戶名
varchar(20)
非空,主鍵
主鍵
number
購買數(shù)量
int
非空
某種商品的購買數(shù)量
color
商品顏色
char(4)
非空
取值范圍白、紅、黃、米白
size
商品尺寸
char(4)
非空
取值范圍S,M,X,XXL
price
價格
double
非空
商品單價
3 實體類定義3.1User.java
public class User {
              String userName;
              String password;
              double account;
              boolean identity;
              public String getUserName() {
                            return userName;
              }
              public void setUserName(String userName) {
                            this.userName = userName;
              }              public String getPassword() {
                            return password;
              }
              public void setPassword(String password) {
                            this.password =  password;
              }
              public double getAccount() {
                            return account;
              }
              public void setAccount(double d) {
                            this.account = d;
              }
              public boolean getIdentity() {
                            return identity;
              }
              public void setIdentity(boolean b) {
                            this.identity = b;
              }
              }
3.1Goods.java
package shop;
public class Goods {
              String goodsID;
              String goodsName;
              int store;
              double price;
              String color;
              String size;
              String image;
              String detail;
              public String getGoodsID() {
                            return goodsID;
              }
              public void setGoodsID(String goodsID) {
                            this.goodsID = goodsID;
              }
              public String getGoodsName() {
                            return goodsName;
              }
              public void setGoodsName(String goodsName) {
                            this.goodsName = goodsName;
              }
              public int getStore() {
                            return store;
              }
              public void setStore(int store) {
                            this.store = store;
              }
              public double getPrice() {
                            return price;
              }
              public void setPrice(double price) {
                            this.price = price;
              }
              public String getColor() {
                            return color;
              }
              public void setColor(String color) {
                            this.color = color;
              }
              public String getSize() {
                            return size;
              }
              public void setSize(String size) {
                            this.size = size;
              }
              public String getImage() {
                            return image;
              }
              public void setImage(String image) {
                            this.image = image;
              }
              public String getDetail() {
                            return detail;
              }
              public void setDetail(String detail) {
                            this.detail = detail;
              }
3.3Shop.java
package shop;
public class Shop {
              private User user = new User();
              private Goods goods = new Goods();
              private int number;
              public User getUser() {
                            return user;
              }
              public void setUser(User user) {
                            this.user = user;
              }
              public Goods getGoods() {
                            return goods;
              }
              public void setGoods(Goods goods) {
                            this.goods = goods;
              }
              public int getNumber() {
                            return number;
              }
              public void setNumber(int number) {
                            this.number = number;
              }
3.4Order.java
package shop;
public class Order {
              private User user=new User();
              private Goods goods=new Goods();
              private String orderID;
              private String orderTime;
              private int number;
              private int pay;            
              public User getUser() {
                            return user;
              }
              public void setUser(User user) {
                            this.user = user;
              }
              public Goods getGoods() {
                            return goods;
              }
              public void setGoods(Goods goods) {
                            this.goods = goods;
              }
              public String getOrderID() {
                            return orderID;
              }
              public void setOrderID(String orderID) {
                            this.orderID = orderID;
              }
              public String getOrderTime() {
                            return orderTime;
              }
              public void setOrderTime(String orderTime) {
                            this.orderTime = orderTime;
              }
              public int getNumber() {
                            return number;
              }
              public void setNumber(int number) {
                            this.number = number;
              }
4 功能類定義——圖形界面實現(xiàn)4.1登錄界面(1)布局框架采用網(wǎng)格布局3行1列,每一行放一個面板,面板采用流水布局,前兩行(用戶名、密碼)采用左對齊,最后一行(按鈕行)采用居中對齊。
1.001.jpg







圖4-1-1登錄界面布局圖

(2)源代碼
public class Load extends JFrame implements ActionListener{
              public Load() {
                            this.init();
                            this.setVisible(true);
                            this.setSize(400, 400);
                            this.setTitle("");
                            //this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
              }
              public void init(){
                            this.setLayout(new GridLayout(3,1));
                            JPanel jp1=new JPanel();
                            load.addActionListener(this);
                  cancel.addActionListener(this);
                  zc.addActionListener(this);
              }
              public void actionPerformed(ActionEvent arg0) {
                            if(arg0.getSource()==load){
                                String userName = userField.getText();
                                System.out.println(userName);
                                String psw = pswField.getText();

                                String sql="select * from userinfo where UserName='"+userName+"'";
                                System.out.println(sql);
                                //加數(shù)據(jù)庫操作代碼
                                try{
                                              ResultSet rs=ConnectionDB.selectData(sql);

                                              if(!rs.next()){
                                                            JOptionPane.showMessageDialog(this,"用戶名錯誤,此用戶名不存在!", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);
                                              } else{
                                                            user.setUserName(rs.getString("" + "userName"));
                                                                      //System.out.println(rs.getString("userName"));
                                                                      user.setAccount(rs.getDouble("account"));
                                                                      user.setPassword(rs.getString("password"));
                                                                      user.setIdentity(rs.getBoolean("identity"));
                                                                      //System.out.println(user.getIdentity());
                                                                      if(user.getPassword().equals(psw)) {
                                                                                    if(user.isIdentity()) {
                                                                                                  GoodsMaintain goodsMaintain=new GoodsMaintain();
                                                                                    }
                                                                                    else {
                                                                                                  Main main=new Main(user);
                                                                                    }
                                                                                    this.dispose();
                                                                      }
                                                                      else {
                                                                                    JOptionPane.showMessageDialog(this, "密碼錯誤", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);
                                                                      }
                                                        }
                                                        ConnectionDB.close();
                                          } catch (SQLException e) {
                                                        e.printStackTrace();}
                                          }else if(arg0.getSource()==cancel){
                                                        userField.setText("");
                                                        pswField.setText("");
                                                        }else if(arg0.getSource()==zc){
                                                                      zhuce zcl=new zhuce(user);
                                                        }}
              public static void main(String[] args) {
                            Load l=new Load();
              }
}
1.002.jpg (3)完成效果截圖







圖4-1-2登錄界面效果圖
4.2 商品信息維護界面(1)布局
先采用邊界布局分為中間C和南邊S,南邊S采用流水布局中間對齊,順次擺放4個按鈕,中間C再次采用邊界布局分為中間CC和南邊CS,CC采用網(wǎng)格布局分成4行1列網(wǎng)格,每個網(wǎng)格上流水布局左對齊,按順次擺放控件;南邊CS采用流水布局左對齊,將標簽“商品描述”和文本域控件放上。
1.003.jpg



圖4-2-1商品信息維護界面布局圖

(2)源代碼
public class GoodsMaintain extends JFrame implements ActionListener{
              public GoodsMaintain() {
                            // TODO Auto-generated constructor stub
                            this.init();
                            this.setVisible(true);
                            this.setSize(500, 500);
                            this.setTitle("");
                            this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
              }
              @Override
              public void actionPerformed(ActionEvent e) {
                            // TODO Auto-generated method stub
                            id=IDField.getText();

                            //查找商品
                            if(e.getSource()==jbsearch){
                                          if(id.equals("")){
                                                        JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
                                          }else{
                                                        sql="select * from goodsinfo where goodsID='"+id+"'";
                                                        rs=(ResultSet) ConnectionDB.selectData(sql);
                                                        try {
                                                                      if(rs.next()){
                                                                                    nameField.setText(rs.getString("goodsName"));
                                                                                    priceField.setText(String.valueOf(rs.getDouble("price")));
                                                                                    imageField.setText(rs.getString("image"));
                                                                                    storeField.setText(String.valueOf(rs.getInt("store")));
                                                                                    colorBox.setEditable(true);
                                                                                    colorBox.setSelectedItem(rs.getString("color"));
                                                                                    sizeBox.setEditable(true);
                                                                                    sizeBox.setSelectedItem(rs.getString("size"));
                                                                                    detailArea.setText(rs.getString("detail"));
                                                                      }else{
                                                                                    JOptionPane.showMessageDialog(this,"商品不存在","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
                                                                      }
                                                                      ConnectionDB.close();
                                                        } catch (HeadlessException e1) {
                                                                      // TODO Auto-generated catch block
                                                                      e1.printStackTrace();
                                                        } catch (SQLException e1) {
                                                                      // TODO Auto-generated catch block
                                                                      e1.printStackTrace();
                                             }
                                          }
                            }else if(e.getSource()==jbupdate){
                                          if(id.equals("")){
                                                        JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
                                          }else{
                                                        goodsName=nameField.getText();
                                                        price=Double.parseDouble(priceField.getText());
                                                        image=imageField.getText();
                                                        store=Integer.parseInt(storeField.getText());
                                                        detail=detailArea.getText();
                                                        sql="update goodsinfo set goodsName='"+goodsName+"',store='"+store+"',price='"+price+"',color='"+color+"',size='"+size+"',image='"+image+"',detail='"+detail+"'where goodsID='"+id+"'";
                                                        ConnectionDB.updateData(sql);
                                                        System.out .println(sql);
                                                        JOptionPane.showMessageDialog(this, "商品修改成功", "系統(tǒng)信息", JOptionPane.INFORMATION_MESSAGE);;
                                                        ConnectionDB.close();
                                                        }
                            }else if(e.getSource()==jbdelete){
                                          if(id.equals("")){
                                                        JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
                                                        }else{
                                                                      sql="delete from goodsinfo where goodsID='"+id+"'";
                                                                      ConnectionDB.updateData(sql);
                                                                      JOptionPane.showMessageDialog(this, "商品刪除成功", "系統(tǒng)信息", JOptionPane.INFORMATION_MESSAGE);;
                                                                      ConnectionDB.close();
                                                                      IDField.setText("");
                                                                      nameField.setText("");
                                                                      priceField.setText("");
                                                                      imageField.setText("");
                                                                      storeField.setText("");
                                                                      colorBox.setEditable(true);
                                                                      colorBox.setSelectedItem("");
                                                                      sizeBox.setEditable(true);
                                                                      sizeBox.setSelectedItem("");
                                                                      detailArea.setText("");
                            }else if(e.getSource()==jbadd){
                                          id=IDField.getText();
                                          if(id.equals("")){
                                                        JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
                                                        }else{
                                                                      sql="select * from goodsinfo where goodsID='"+id+"'";
                                                                      rs=(ResultSet) ConnectionDB.selectData(sql);
                                                                                    try {
                                                                                                  if(rs.next()){
                                                                                                                JOptionPane.showMessageDialog(this,"商品信息已存在","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
                                                                                                                ConnectionDB.close();
                                                                                                                }else{
                                                                                                                ConnectionDB.close();            
                                                                                                                goodsName=nameField.getText();
                                                                                                                price=Double.parseDouble(priceField.getText());
                                                                                                                image=imageField.getText();
                                                                                                                store=Integer.parseInt(storeField.getText());
                                                                                                                detail=detailArea.getText();
                                                                                                                sql="insert into goodsinfo(goodsID,goodsName,store,price,color,size,image,detail) values('"+id+"','"+goodsName+"','"+store+"','"+price+"','"+color+"','"+size+"','"+image+"','"+detail+"')";
                                                                                                                ConnectionDB.updateData(sql);
                                                                                                                JOptionPane.showMessageDialog(this,"商品信息添加成功","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
                                                                                                                ConnectionDB.close();}
                                                                                    } catch (HeadlessException e1) {
                                                                                                  e1.printStackTrace();
                                                                                    } catch (SQLException e1) {
                                                                                                  e1.printStackTrace();
                                                                                    }
              }


(3)完成效果截圖
1.004.jpg











圖4-2-2商品信息維護界面效果圖
4.3主頁面(1)布局
先采用邊界布局分為北邊N、中間C、西邊W和南邊S。北邊N采用邊界布局分為中間NC和南邊NS,NC流水布局中間對齊,放jlLogo,NS采用1行兩列網(wǎng)格布局,左側(cè)網(wǎng)格流水布局左對齊,放標簽jl,右側(cè)網(wǎng)格流水布局右對齊,放標簽、文本框nameField、按鈕jbsearch。中間C采用2行3列網(wǎng)格布局,用循環(huán)放mp。西邊W采用3行1列網(wǎng)格布局,每個網(wǎng)格流水布局中間對齊,放按鈕jbadd、jbshop和jborder。南邊S流水布局中間對齊放標簽。
1.005.jpg



圖4-3-1主頁面布局圖

(2)源代碼
              public void actionPerformed(ActionEvent e) {
                            // TODO Auto-generated method stub
                            if(e.getSource()==jbadd){
                                          Rechange rechange=new Rechange(user);
                            }else if(e.getSource()==jbshop){
                                          ShopSearch shopSearch=new ShopSearch(user);
                            }
              else if(e.getSource()==jbsearch){
                                          if(nameField.getText().trim().equals("")){
                                                        JOptionPane.showMessageDialog(this,"商品名稱不為空","系統(tǒng)消息",JOptionPane.INFORMATION_MESSAGE);
                                          }else{
                                                        sql="select * from goodsinfo where goodsName='"+nameField.getText().trim()+"'";
                                                        System.out.println(sql);
                                                        //st=conn.createStatement();
                                              //rs=st.executeQuery(sql);
                                                        rs=ConnectionDB.selectData(sql);//通過ConnectionDB連接
                                                        try {
                                                                      if(rs.next()){//進行判斷集合中是否有數(shù)據(jù)存在 rs.next()
                                                                                    goods.setGoodsID(rs.getString("goodsID"));
                                                                                    goods.setGoodsName(rs.getString("goodsName"));
                                                                                    goods.setStore(rs.getInt("store"));
                                                                                    goods.setPrice(rs.getDouble("price"));
                                                                                    goods.setColor(rs.getString("color"));
                                                                                    goods.setSize(rs.getString("size"));
                                                                                    goods.setImage(rs.getString("image"));
                                                                                    goods.setSize(rs.getString("size"));
                                                                                    goods.setDetail(rs.getString("detail"));
                                                                                    GoodsBuy GoodsBuy=new GoodsBuy(goods,user);
                                                                      }else{
                                                                                    JOptionPane.showMessageDialog(this,"商品不存在","系統(tǒng)消息",JOptionPane.INFORMATION_MESSAGE);}                                         
                                                                      ConnectionDB.close();
                                                        } catch (SQLException e1) {
                                                                      // TODO Auto-generated catch block
                                                                      e1.printStackTrace();
                                                        }
                            }else if(e.getSource()==(jborder)){
                                          OrderAllSearch orderAllSearch=new OrderAllSearch(user);
                            }}
1.006.jpg (3)完成效果截圖











圖4-3-2主頁面完成效果圖
4.4 商品購買頁面(1)布局
先采用邊界布局分為中間C和南邊S。中間C采用1行2列網(wǎng)格布局,左側(cè)網(wǎng)格流水布局中間對齊,放標簽jliamge,右側(cè)網(wǎng)格采用7行1列網(wǎng)格布局,每一行再采用流水布局左對齊,將對應(yīng)組件放上去。南邊S流水布局中間對齊,將組件放上。
1.007.jpg



圖4-4-1購買界面布局圖
(2)源代碼
public class GoodsBuy extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent e) {
              if(e.getSource()==jbadd){
                            sql="insert into shopinfo values('"+goods.getGoodsID()+"','"+goods.getGoodsName()+"','"+user.getUserName()+"','"+Integer.parseInt(nubmerField.getText())+"','"+goods.getColor()+"','"+goods.getSize()+"','"+goods.getPrice()+"')";
                            ConnectionDB.updateData(sql);
                            JOptionPane.showMessageDialog(this,"添加成功","系統(tǒng)消息",JOptionPane.INFORMATION_MESSAGE);
                            ConnectionDB.close();
              }else if(e.getSource()==jborder){
                            //OrderSearch or = new OrderSearch(order,user,goods);
                            String orderid=null;
                            sql="select max(orderID) as id from orderinfo";
                            rs=ConnectionDB.selectData(sql);
                            try {
                                          if(rs.next()){
                                                        System.out.println(orderid);
                                                        orderid=String.valueOf(Integer.parseInt(rs.getString("id"))+1);
                                          }else{
                                                        orderid="10001";
                                                        System.out.println(orderid);
                                          }
                            } catch (SQLException e1) {
                                          // TODO Auto-generated catch block
                                          e1.printStackTrace();
                            }
                            ConnectionDB.close();
                            Date date=new Date();
                            String orderTime=String.valueOf(date.getYear()+1900);
                            orderTime=orderTime+"-"+String.valueOf(date.getMonth()+1);
                            orderTime=orderTime+"-"+String.valueOf(date.getDate());
                            sql="insert into orderinfo values('"+orderid+"','"+goods.getGoodsID()+"','"+goods.getGoodsName()+"','"+orderTime+"','"+user.getUserName()+"','"+Integer.parseInt(nubmerField.getText())+"','"+goods.getColor()+"','"+goods.getSize()+"','0','"+goods.getPrice()+"')";
                            System.out.println(sql);
                            ConnectionDB.updateData(sql);
                            ConnectionDB.close();
                            order.setOrderID(orderid);
                            System.out.println(orderid);
                            order.setGoods(goods);
                            order.setUser(user);
                            order.setNumber(Integer.parseInt(nubmerField.getText()));
                            order.setPay(0);
                            order.setOrderTime(orderTime);
                            OrderlSearch orderSearch=new OrderlSearch(order,user);
              }
}
}
1.008.jpg (3)完成效果截圖











1.010.jpg
圖4-4-2購買界面完成效果圖
4.5 單筆訂單支付界面(1)布局
先采用邊界布局分為北邊N、中間C和南邊S。北邊N流水布局左對齊,放標簽jluser。中間C采用4行2列網(wǎng)格布局,每一網(wǎng)格再采用流水布局左對齊,放置組件。南邊S流水布局右對齊,將按鈕jbdelete和jbpay放上。
1.009.jpg


圖4-5-1單筆訂單完成布局圖
(2)源代碼
public class OrderlSearch extends JFrame implements ActionListener{
              public void actionPerformed(ActionEvent e) {
                            if(e.getSource()==jbdelete){
                                          sql="delete from orderinfo where orderID='"+order.getOrderID()+"'";
                                          ConnectionDB.updateData(sql);
                                          JOptionPane.showMessageDialog(this, "刪除成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);
                                          ConnectionDB.close();
                            }else if(e.getSource()==jbpay){
                                          double account=user.getAccount();
                                          double all=goods.getPrice()*order.getNumber();
                                          if(account<all){[ align]" joptionpane.showmessagedialog(this,="" "余額不足",="" "系統(tǒng)消息",="" joptionpane.information_message);[="" }else{[="" sql="update userinfo set account='" +(account-all)+"'="" where="" username=""+user.getUserName()+"" ";[="" connectiondb.updatedata(sql);[="" connectiondb.close();[="" +order.getorderid()+"'";[="" +(goods.getstore()-order.getnumber())+"'="" goodsid=""+goods.getGoodsID()+"" "支付成功",="" joptionpane.information_message);}[="" [attachimg]52381[="" attachimg][="" align]








圖4-5-2單筆訂單完成效果圖4.6 多筆訂單支付界面(1)布局先采用邊界布局分為中間C和南邊S。中間C采用流水布局中間對齊,然后放置面板,面板采用6行7列網(wǎng)格布局,每一網(wǎng)格再采用流水布局左對齊,放置標簽組件。南邊S流水布局右對齊,將按鈕jbdelete和jbpay放上。 1.011.jpg


圖4-6-1多筆訂單支付完成布局圖
(2)源代碼
  1. public class OrderAllSearch extends JFrame implements ActionListener {

  2.               public void actionPerformed(ActionEvent arg0) {

  3.                             if (arg0.getSource() == jbdelete) {

  4.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  5.                                                         if (jcb[i].isSelected()) {

  6.                                                                       order = (Order) list.get(i);

  7.                                                                       sql = "delete from orderinfo where goodsID='" + order.getGoods().getGoodsID() + "' and orderID='"

  8.                                                                                                   + order.getOrderID() + "' and userName='" + order.getUser().getUserName()

  9.                                                                                                   + "' and orderTime='" + order.getOrderTime() + "'";



  10.                                                                       JOptionPane.showMessageDialog(this, "刪除成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);

  11.                                                                       ConnectionDB.updateData(sql);

  12.                                                                       ConnectionDB.close();

  13.                                                         }

  14.                                           }



  15.                             } else if (arg0.getSource() == jbpay) {

  16.                                           double all = 0;

  17.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  18.                                                         if (jcb[i].isSelected()) {

  19.                                                                       order = (Order) list.get(i);

  20.                                                                       all = all + order.getNumber() * order.getGoods().getPrice();



  21.                                                         }

  22.                                           }

  23.                                           double account = user.getAccount();



  24.                                           if (account < all) {

  25.                                                         JOptionPane.showMessageDialog(this, "余額不足", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);

  26.                                           } else {

  27.                                                         for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  28.                                                                       if (jcb[i].isSelected()) {

  29.                                                                                     order = (Order) list.get(i);

  30.                                                                                     sql = "update orderinfo set pay='1' where goodsID='" + order.getGoods().getGoodsID()

  31.                                                                                                                 + "' and orderID='" + order.getOrderID() + "' and userName='"

  32.                                                                                                                 + order.getUser().getUserName() + "' and orderTime='" + order.getOrderTime() + "'";

  33.                                                                                     ConnectionDB.updateData(sql);

  34.                                                                                     ConnectionDB.close();

  35.                                                                       }

  36.                                                         }

  37.                                                         sql = "update userinfo set account='" + (account - all) + "' where userName='" + user.getUserName()

  38.                                                                                     + "'";

  39.                                                         ConnectionDB.updateData(sql);

  40.                                                         ConnectionDB.close();

  41.                                                         JOptionPane.showMessageDialog(this, "成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);

  42.                                           }

  43.                             }

  44.               }



  45. }
復(fù)制代碼


(3)完成效果截圖
1.012.jpg
圖4-6-2多筆訂單支付完成效果圖4.7購物車維護界面(1)布局 1.013.jpg 先采用邊界布局分為中間C和南邊S。中間C采用流水布局中間對齊,然后放置面板,面板采用6行7列網(wǎng)格布局,每一網(wǎng)格再采用流水布局左對齊,放置標簽組件。南邊S流水布局右對齊,將按鈕jbdelete、jbpay和jborder放上。




圖4-7-1購物車維護界面完成布局圖(2)源代碼
  1. public class ShopSearch extends JFrame implements ActionListener {

  2.               public void actionPerformed(ActionEvent arg0) {

  3.                             if (arg0.getSource() == jbdelete) {

  4.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  5.                                                         if (jcb[i].isSelected()) {

  6.                                                                       shop = (Shop) list.get(i);

  7.                                                                       sql = "delete from shopinfo where goodsID='" + shop.getGoods().getGoodsID() + "'and userName='"

  8.                                                                                                   + shop.getUser().getUserName() + "'";

  9.                                                                       ConnectionDB.updateData(sql);

  10.                                                                       ConnectionDB.close();

  11.                                                                       JOptionPane.showMessageDialog(this, "刪除成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);

  12.                                                         }

  13.                                           }



  14.                             } else if (arg0.getSource() == jbupdate) {

  15.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  16.                                                         if (jcb[i].isSelected()) {

  17.                                                                       shop = (Shop) list.get(i);

  18.                                                                       ShopUpdate shopUpdate = new ShopUpdate(shop);



  19.                                                         }

  20.                                           }

  21.                             } else if (arg0.getSource() == jborder) {

  22.                                           String orderid = null;

  23.                                           sql = "select max(orderID) as id from orderinfo";

  24.                                           rs = ConnectionDB.selectData(sql);

  25.                                           try {

  26.                                                         if (rs.next()) {

  27.                                                                       orderid = String.valueOf(Integer.parseInt(rs.getString("id")) + 1);

  28.                                                         } else {

  29.                                                                       orderid = "999";

  30.                                                         }

  31.                                           } catch (SQLException e1) {

  32.                                                         // TODO Auto-generated catch block

  33.                                                         e1.printStackTrace();

  34.                                           }

  35.                                           ConnectionDB.close();

  36.                                           Date date = new Date();

  37.                                           String orderTime = String.valueOf(date.getYear() + 1900) + "-" + String.valueOf(date.getMonth() + 1) + "-"

  38.                                                                       + String.valueOf(date.getDay());

  39.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  40.                                                         if (jcb[i].isSelected()) {

  41.                                                                       shop = (Shop) list.get(i);

  42.                                                                       Goods goods = shop.getGoods();

  43.                                                                       sql = "insert into orderinfo values('" + orderid + "','" + goods.getGoodsID() + "','"

  44.                                                                                                   + goods.getGoodsName() + "','" + orderTime + "','" + user.getUserName() + "','"

  45.                                                                                                   + shop.getNumber() + "','" + goods.getColor() + "','" + goods.getSize() + "','0','"

  46.                                                                                                   + goods.getPrice() + "')";

  47.                                                                       ConnectionDB.updateData(sql);

  48.                                                                       ConnectionDB.close();

  49.                                                                       JOptionPane.showMessageDialog(this, "生成成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);

  50.                                                         }}
復(fù)制代碼


(3)完成效果截圖 1.014.jpg







圖4-7-2購物車維護界面完成效果圖4.8購物信息修改界面界面(1)布局先采用邊界布局分為中間C和南邊S。中間C采用3行2列網(wǎng)格布局,每一網(wǎng)格再采用流水布局左對齊,放置組件。南邊S流水布局右對齊,將按鈕jbupdate放上。 1.015.jpg


圖4-8-1購物車修改界面完成布局圖(2)源代碼
  1. public class ShopSearch extends JFrame implements ActionListener {

  2.               public void actionPerformed(ActionEvent arg0) {

  3.                             if (arg0.getSource() == jbdelete) {

  4.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  5.                                                         if (jcb[i].isSelected()) {

  6.                                                                       shop = (Shop) list.get(i);

  7.                                                                       sql = "delete from shopinfo where goodsID='" + shop.getGoods().getGoodsID() + "'and userName='"

  8.                                                                                                   + shop.getUser().getUserName() + "'";

  9.                                                                       ConnectionDB.updateData(sql);

  10.                                                                       ConnectionDB.close();

  11.                                                                       JOptionPane.showMessageDialog(this, "刪除成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);

  12.                                                         }

  13.                                           }



  14.                             } else if (arg0.getSource() == jbupdate) {

  15.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  16.                                                         if (jcb[i].isSelected()) {

  17.                                                                       shop = (Shop) list.get(i);

  18.                                                                       ShopUpdate shopUpdate = new ShopUpdate(shop);



  19.                                                         }

  20.                                           }

  21.                             } else if (arg0.getSource() == jborder) {

  22.                                           String orderid = null;

  23.                                           sql = "select max(orderID) as id from orderinfo";

  24.                                           rs = ConnectionDB.selectData(sql);

  25.                                           try {

  26.                                                         if (rs.next()) {

  27.                                                                       orderid = String.valueOf(Integer.parseInt(rs.getString("id")) + 1);

  28.                                                         } else {

  29.                                                                       orderid = "999";

  30.                                                         }

  31.                                           } catch (SQLException e1) {

  32.                                                         // TODO Auto-generated catch block

  33.                                                         e1.printStackTrace();

  34.                                           }

  35.                                           ConnectionDB.close();

  36.                                           Date date = new Date();

  37.                                           String orderTime = String.valueOf(date.getYear() + 1900) + "-" + String.valueOf(date.getMonth() + 1) + "-"

  38.                                                                       + String.valueOf(date.getDay());

  39.                                           for (int i = 0; i < (10 < list.size() ? 10 : list.size()); i++) {

  40.                                                         if (jcb[i].isSelected()) {

  41.                                                                       shop = (Shop) list.get(i);

  42.                                                                       Goods goods = shop.getGoods();

  43.                                                                       sql = "insert into orderinfo values('" + orderid + "','" + goods.getGoodsID() + "','"

  44.                                                                                                   + goods.getGoodsName() + "','" + orderTime + "','" + user.getUserName() + "','"

  45.                                                                                                   + shop.getNumber() + "','" + goods.getColor() + "','" + goods.getSize() + "','0','"

  46.                                                                                                   + goods.getPrice() + "')";

  47.                                                                       ConnectionDB.updateData(sql);

  48.                                                                       ConnectionDB.close();

  49.                                                                       JOptionPane.showMessageDialog(this, "生成成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);

  50.                                                         }}}
復(fù)制代碼


1.016.jpg (3)完成效果截圖








圖4-8-2購物車修改界面完成效果圖
4.9 充值界面界面(1)布局先采用邊界布局分為中間C和南邊S。中間C采用2行2列網(wǎng)格布局,每一網(wǎng)格再采用流水布局左對齊,放置組件。南邊S流水布局右對齊,將按鈕jbrechange放上。 1.017.jpg


圖4-9-1充值頁面完成效果圖(2)源代碼public class Rechange extends JFrame implements  ActionListener{              public void actionPerformed(ActionEvent e) {                            // TODO Auto-generated method stub                            User user=new User();                            String name=jlname.getText();
                            //double q=Double.parseDouble(moneyField.getText());                            if(e.getSource()==jbrechange){                                          int n=JOptionPane.showConfirmDialog(this, "是否確認充值?", "系統(tǒng)消息", JOptionPane.YES_NO_OPTION);                                          if(n==JOptionPane.YES_OPTION){                                                        String sql = "select * from userinfo where userName='"+name+"'";                                                        System.out.println(sql);
                                                        try{                                                                      ResultSet rs = ConnectionDB.selectData(sql);
                                                                      if(!rs.next()){                                                                                    JOptionPane.showMessageDialog(this, "此用戶不存在!","系統(tǒng)消息",JOptionPane.WARNING_MESSAGE);                                                                      }else if(moneyField.getText().equals("")){                                                                                    JOptionPane.showMessageDialog(this, "請輸入充值金額!","系統(tǒng)消息",JOptionPane.WARNING_MESSAGE);                                                                      }                                                                      else{                                                                                    double acc = rs.getDouble("account")+Double.parseDouble(moneyField.getText());                                                                                    sql="update userinfo set account='"+acc+"' where userName='"+name+"'";                                                                          //sql = "select account from userinfo where userName='"+name+"'";                                                                          jlaccount.setText(String.valueOf(rs.getDouble("account")));                                                                                    ConnectionDB.updateData(sql);                                                                                    ConnectionDB.close();                                                                                    JOptionPane.showMessageDialog(this, "充值成功!","系統(tǒng)消息",JOptionPane.WARNING_MESSAGE);                                                                      }                                                        }catch(SQLException e1){                                                                      e1.printStackTrace();                                          }                            }              }}(3)完成效果截圖 1.018.jpg 圖4-9-2充值頁面完成效果圖
5 功能類定義——數(shù)據(jù)庫操作實現(xiàn)(1)數(shù)據(jù)庫操作(1)數(shù)據(jù)庫安裝安裝MySql數(shù)據(jù)庫(2)導(dǎo)入數(shù)據(jù)              將數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(2)源代碼
package shop;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class ConnectionDB {              static Connection con=null;              static Statement st=null;              static ResultSet rs=null;              public static ResultSet selectData(String sql){                            try {                                          Class.forName("com.mysql.jdbc.Driver");//"com.mysql.jdbc.Driver"con=DriverManager.getConnection("jdbc:mysql://localhost/shop?user=root&password=123456&useUnicode=true&characterEncoding=gbk");                                          st=con.createStatement();                                          rs=st.executeQuery(sql);                                          return rs;                            } catch (SQLException e) {                                          // TODO Auto-generated catch block                                          e.printStackTrace();                            } catch (ClassNotFoundException e) {                                          // TODO Auto-generated catch block                                          e.printStackTrace();                            }                            return null;              }              public static void updateData(String sql){                            try {                                          Class.forName("com.mysql.jdbc.Driver");              con=DriverManager.getConnection("jdbc:mysql://localhost/shop?user=root&password=123456&useUnicode=true&characterEncoding=gbk");                                          st=con.createStatement();                                          st.execute(sql);                            } catch (SQLException e) {                                          // TODO Auto-generated catch block                                          e.printStackTrace();                            } catch (ClassNotFoundException e) {                                          // TODO Auto-generated catch block                                          e.printStackTrace();                            }              }              public static void close(){                            try {                                          rs.close();                                          st.close();                                          con.close();                            } catch (SQLException e) {                                          // TODO Auto-generated catch block                                          e.printStackTrace();                            }}}6 總結(jié)通過這次實訓(xùn)我的體會歸納為以下4點:1.態(tài)度第一擺正自己的心態(tài),不要以為什么東西上網(wǎng)搜搜就可以了,一定要有自己的東西。只有自己付出過,當JAVA購物系統(tǒng)程序運行成功時的那種喜悅才會令自己有一種莫名的自豪感。態(tài)度決定一切!2.興趣是關(guān)鍵我的學(xué)習(xí)完全是興趣導(dǎo)向的。因為有興趣,所以我會很想充分理解一切細節(jié)。又因為理解,所以許多原本片片斷斷的知識都可以漸漸互相融會貫通,累積技術(shù)能量,理論和實務(wù)之間的藩籬被打破了,學(xué)習(xí)效率倍增。學(xué)習(xí)并快樂著!3.敢于挑戰(zhàn)不安于現(xiàn)成的程序,要敢于用多種方法實現(xiàn)一個目的,F(xiàn)在的網(wǎng)絡(luò)科技很發(fā)達,想要一個源程序的確很簡單,所以很多人都是在自己都不明白題目要求時,就可以在網(wǎng)上搜到一模一樣的代碼,根本沒有自己的東西。挑戰(zhàn)自我是項艱巨的任務(wù)。只有堅持自己多看代碼多寫程序才會有更多的收獲。4.不懈追求要對源代碼進行不斷地完善,要盡可能地實現(xiàn)課題所要求的功能。對初學(xué)者來說,大量地寫程序是必要的,但過了某個階段之后,寫程序所帶來的技術(shù)能力成長已經(jīng)到了極限,還不如多花一點時間看書,學(xué)新技術(shù)和新觀念。可以從實現(xiàn)源程序功能著手,比如添加寫模塊啊什么的,實現(xiàn)更多功能。看著自己編的程序能成功運行,這樣自己會更感興趣,也就會樂此不疲


回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表