久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2920|回復: 0
收起左側

Java薯片購物管理系統的設計與實現 課程設計論文下載

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

這是
大學實訓的內容,完整的java程序。

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

下面是本設計的部分內容預覽:
大連科技學院
Java程序設計課程設計(B)

題  目基于Java的薯片購物管理系統的設計與實現

學生姓名專業班級

指導教師   樊曉勇  職    稱   副教授      

所在單位   信息科學學院物聯網工程教研室      

教研室主任           孫 琦               


完成日期  2017 年1月 6 日


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


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


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


設計報告結構與內容
(20分)
A:結構清晰,內容充實B:結構完整,內容較充實
C:結構與內容完整D:結構與內容較完整
E:結構混亂,內容欠缺


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



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




綜 合  評 定:



(優、良、中、及格、不及格)
































指導教師簽字:





2017年1月6日









目  錄

1薯片購物系統概述              1

1.1              系統簡介

1.2 系統開發所采用的技術

2數據庫結構

2.1用戶表

2.2商品表

2.3訂單表

2.4購物車表

3 實體類定義

3.1User.java

3.1Goods.java

3.3Shop.java

4 功能類定義——圖形界面實現

4.1登錄界面

4.2 商品信息維護界面

4.3主頁面

4.4 商品購買頁面

4.5 單筆訂單支付界面

4.6 多筆訂單支付界面

4.7購物車維護界面

4.8購物信息修改界面界面

4.9 充值界面界面

5 功能類定義——數據庫操作實現

6 總結






1





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





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

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

2.3訂單表
字段名(列名)
中文描述
數據類型
約束
描述
orderID
訂單編號
char(5)
主鍵、非空
主鍵
goodsID
商品編號
char(5)
主鍵、非空
主鍵
goodsName
商品名
varchar(20)
非空
商品名字
orderTime
訂單日期
char(10)
主鍵、非空
主鍵
userName
用戶名
varchar(20)
主鍵、非空
主鍵
number
購買數量
int
非空
某種商品的購買數量
color
商品顏色
char(4)
非空
取值范圍白、紅、黃、米白
size
商品尺寸
char(4)
非空
取值范圍S,M,X,XXL
pay
支付狀態
boolean
非空
已支付該項為“true”,未支付為“false”
price
價格
double
非空
商品單價
2.4購物車表
字段名(列名)
中文描述
數據類型
約束
描述
goodsID
商品編號
char(10)
主鍵、非空
主鍵
goodsName
商品名
varchar(20)
非空
商品名字
userName
用戶名
varchar(20)
非空,主鍵
主鍵
number
購買數量
int
非空
某種商品的購買數量
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 功能類定義——圖形界面實現4.1登錄界面(1)布局框架采用網格布局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);
                                //加數據庫操作代碼
                                try{
                                              ResultSet rs=ConnectionDB.selectData(sql);

                                              if(!rs.next()){
                                                            JOptionPane.showMessageDialog(this,"用戶名錯誤,此用戶名不存在!", "系統消息", 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, "密碼錯誤", "系統消息", 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采用網格布局分成4行1列網格,每個網格上流水布局左對齊,按順次擺放控件;南邊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不能為空","系統信息",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,"商品不存在","系統信息",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不能為空","系統信息",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, "商品修改成功", "系統信息", JOptionPane.INFORMATION_MESSAGE);;
                                                        ConnectionDB.close();
                                                        }
                            }else if(e.getSource()==jbdelete){
                                          if(id.equals("")){
                                                        JOptionPane.showMessageDialog(this,"商品ID不能為空","系統信息",JOptionPane.INFORMATION_MESSAGE);
                                                        }else{
                                                                      sql="delete from goodsinfo where goodsID='"+id+"'";
                                                                      ConnectionDB.updateData(sql);
                                                                      JOptionPane.showMessageDialog(this, "商品刪除成功", "系統信息", 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不能為空","系統信息",JOptionPane.INFORMATION_MESSAGE);
                                                        }else{
                                                                      sql="select * from goodsinfo where goodsID='"+id+"'";
                                                                      rs=(ResultSet) ConnectionDB.selectData(sql);
                                                                                    try {
                                                                                                  if(rs.next()){
                                                                                                                JOptionPane.showMessageDialog(this,"商品信息已存在","系統信息",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,"商品信息添加成功","系統信息",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行兩列網格布局,左側網格流水布局左對齊,放標簽jl,右側網格流水布局右對齊,放標簽、文本框nameField、按鈕jbsearch。中間C采用2行3列網格布局,用循環放mp。西邊W采用3行1列網格布局,每個網格流水布局中間對齊,放按鈕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,"商品名稱不為空","系統消息",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()){//進行判斷集合中是否有數據存在 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,"商品不存在","系統消息",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列網格布局,左側網格流水布局中間對齊,放標簽jliamge,右側網格采用7行1列網格布局,每一行再采用流水布局左對齊,將對應組件放上去。南邊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,"添加成功","系統消息",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列網格布局,每一網格再采用流水布局左對齊,放置組件。南邊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, "刪除成功", "系統消息", 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,="" "余額不足",="" "系統消息",="" 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列網格布局,每一網格再采用流水布局左對齊,放置標簽組件。南邊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, "刪除成功", "系統消息", 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, "余額不足", "系統消息", 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, "成功", "系統消息", JOptionPane.INFORMATION_MESSAGE);

  42.                                           }

  43.                             }

  44.               }



  45. }
復制代碼


(3)完成效果截圖
1.012.jpg
圖4-6-2多筆訂單支付完成效果圖4.7購物車維護界面(1)布局 1.013.jpg 先采用邊界布局分為中間C和南邊S。中間C采用流水布局中間對齊,然后放置面板,面板采用6行7列網格布局,每一網格再采用流水布局左對齊,放置標簽組件。南邊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, "刪除成功", "系統消息", 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, "生成成功", "系統消息", JOptionPane.INFORMATION_MESSAGE);

  50.                                                         }}
復制代碼


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







圖4-7-2購物車維護界面完成效果圖4.8購物信息修改界面界面(1)布局先采用邊界布局分為中間C和南邊S。中間C采用3行2列網格布局,每一網格再采用流水布局左對齊,放置組件。南邊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, "刪除成功", "系統消息", 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, "生成成功", "系統消息", JOptionPane.INFORMATION_MESSAGE);

  50.                                                         }}}
復制代碼


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








圖4-8-2購物車修改界面完成效果圖
4.9 充值界面界面(1)布局先采用邊界布局分為中間C和南邊S。中間C采用2行2列網格布局,每一網格再采用流水布局左對齊,放置組件。南邊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, "是否確認充值?", "系統消息", 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, "此用戶不存在!","系統消息",JOptionPane.WARNING_MESSAGE);                                                                      }else if(moneyField.getText().equals("")){                                                                                    JOptionPane.showMessageDialog(this, "請輸入充值金額!","系統消息",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, "充值成功!","系統消息",JOptionPane.WARNING_MESSAGE);                                                                      }                                                        }catch(SQLException e1){                                                                      e1.printStackTrace();                                          }                            }              }}(3)完成效果截圖 1.018.jpg 圖4-9-2充值頁面完成效果圖
5 功能類定義——數據庫操作實現(1)數據庫操作(1)數據庫安裝安裝MySql數據庫(2)導入數據              將數據導入到數據庫(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 總結通過這次實訓我的體會歸納為以下4點:1.態度第一擺正自己的心態,不要以為什么東西上網搜搜就可以了,一定要有自己的東西。只有自己付出過,當JAVA購物系統程序運行成功時的那種喜悅才會令自己有一種莫名的自豪感。態度決定一切!2.興趣是關鍵我的學習完全是興趣導向的。因為有興趣,所以我會很想充分理解一切細節。又因為理解,所以許多原本片片斷斷的知識都可以漸漸互相融會貫通,累積技術能量,理論和實務之間的藩籬被打破了,學習效率倍增。學習并快樂著!3.敢于挑戰不安于現成的程序,要敢于用多種方法實現一個目的。現在的網絡科技很發達,想要一個源程序的確很簡單,所以很多人都是在自己都不明白題目要求時,就可以在網上搜到一模一樣的代碼,根本沒有自己的東西。挑戰自我是項艱巨的任務。只有堅持自己多看代碼多寫程序才會有更多的收獲。4.不懈追求要對源代碼進行不斷地完善,要盡可能地實現課題所要求的功能。對初學者來說,大量地寫程序是必要的,但過了某個階段之后,寫程序所帶來的技術能力成長已經到了極限,還不如多花一點時間看書,學新技術和新觀念?梢詮膶崿F源程序功能著手,比如添加寫模塊啊什么的,實現更多功能。看著自己編的程序能成功運行,這樣自己會更感興趣,也就會樂此不疲


回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品在线播放 | 在线免费观看色 | 在线观看国产视频 | 国产欧美精品一区二区三区 | 国产亚洲一区二区在线观看 | 欧美一区二区免费在线 | 成人午夜免费视频 | 天天干天天爱天天操 | 欧美福利| 中文字幕第100页 | 四虎伊人 | 五月天天色 | 日韩精品一区二区久久 | 日韩电影一区 | 久草在线 | 日本小视频网站 | 欧美成人免费电影 | 人人爽人人草 | 波多野结衣一区二区三区 | 欧产日产国产精品国产 | 欧美一区二区免费 | 国产在线观看网站 | 欧美在线亚洲 | 亚洲精品一区中文字幕 | 凹凸日日摸日日碰夜夜 | 成人在线免费观看 | 久久精品这里精品 | 久久在线精品 | 亚洲综合视频 | 免费国产网站 | 特黄小视频 | 国产高清视频在线播放 | 第四色播日韩第一页 | 色婷婷综合久久久久中文一区二区 | 国产午夜精品一区二区三区 | 国产日韩欧美精品一区二区三区 | 99精品国自产在线 | 国产一级淫片免费视频 | 在线三级网址 | 成人欧美一区二区三区黑人孕妇 | 久久久久久久91 |