找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2858|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

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

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主

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

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

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

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

學(xué)生姓名專(zhuān)業(yè)班級(jí)

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

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

教研室主任           孫 琦               


完成日期  2017 年1月 6 日


課程設(shè)計(jì)評(píng)分標(biāo)準(zhǔn)
項(xiàng)目
評(píng)價(jià)
成績(jī)
出勤與工作態(tài)度(20分)
A:沒(méi)有缺勤,工作態(tài)度積極主動(dòng)B:缺勤一次,工作態(tài)度良好
C:缺勤二次,工作態(tài)度較好D:缺勤二次,工作態(tài)度較差
E:出勤狀況與工作態(tài)度差


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


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


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


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



項(xiàng)目成績(jī)?cè)u(píng)定標(biāo)準(zhǔn):
A:成績(jī)給定17-20分,B:成績(jī)給定13-16分,C:成績(jī)給定9-12分,D:成績(jī)給定5-8,
E:成績(jī)給定0-4分。




綜 合  評(píng) 定:



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
































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





2017年1月6日









目  錄

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

1.1              系統(tǒng)簡(jiǎn)介

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

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

2.1用戶(hù)表

2.2商品表

2.3訂單表

2.4購(gòu)物車(chē)表

3 實(shí)體類(lèi)定義

3.1User.java

3.1Goods.java

3.3Shop.java

4 功能類(lèi)定義——圖形界面實(shí)現(xiàn)

4.1登錄界面

4.2 商品信息維護(hù)界面

4.3主頁(yè)面

4.4 商品購(gòu)買(mǎi)頁(yè)面

4.5 單筆訂單支付界面

4.6 多筆訂單支付界面

4.7購(gòu)物車(chē)維護(hù)界面

4.8購(gòu)物信息修改界面界面

4.9 充值界面界面

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

6 總結(jié)






1





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





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

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

2.3訂單表
字段名(列名)
中文描述
數(shù)據(jù)類(lèi)型
約束
描述
orderID
訂單編號(hào)
char(5)
主鍵、非空
主鍵
goodsID
商品編號(hào)
char(5)
主鍵、非空
主鍵
goodsName
商品名
varchar(20)
非空
商品名字
orderTime
訂單日期
char(10)
主鍵、非空
主鍵
userName
用戶(hù)名
varchar(20)
主鍵、非空
主鍵
number
購(gòu)買(mǎi)數(shù)量
int
非空
某種商品的購(gòu)買(mǎi)數(shù)量
color
商品顏色
char(4)
非空
取值范圍白、紅、黃、米白
size
商品尺寸
char(4)
非空
取值范圍S,M,X,XXL
pay
支付狀態(tài)
boolean
非空
已支付該項(xiàng)為“true”,未支付為“false”
price
價(jià)格
double
非空
商品單價(jià)
2.4購(gòu)物車(chē)表
字段名(列名)
中文描述
數(shù)據(jù)類(lèi)型
約束
描述
goodsID
商品編號(hào)
char(10)
主鍵、非空
主鍵
goodsName
商品名
varchar(20)
非空
商品名字
userName
用戶(hù)名
varchar(20)
非空,主鍵
主鍵
number
購(gòu)買(mǎi)數(shù)量
int
非空
某種商品的購(gòu)買(mǎi)數(shù)量
color
商品顏色
char(4)
非空
取值范圍白、紅、黃、米白
size
商品尺寸
char(4)
非空
取值范圍S,M,X,XXL
price
價(jià)格
double
非空
商品單價(jià)
3 實(shí)體類(lèi)定義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 功能類(lèi)定義——圖形界面實(shí)現(xiàn)4.1登錄界面(1)布局框架采用網(wǎng)格布局3行1列,每一行放一個(gè)面板,面板采用流水布局,前兩行(用戶(hù)名、密碼)采用左對(duì)齊,最后一行(按鈕行)采用居中對(duì)齊。







圖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ù)庫(kù)操作代碼
                                try{
                                              ResultSet rs=ConnectionDB.selectData(sql);

                                              if(!rs.next()){
                                                            JOptionPane.showMessageDialog(this,"用戶(hù)名錯(cuò)誤,此用戶(hù)名不存在!", "系統(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, "密碼錯(cuò)誤", "系統(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();
              }
}
(3)完成效果截圖







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



圖4-2-1商品信息維護(hù)界面布局圖

(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)完成效果截圖











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



圖4-3-1主頁(yè)面布局圖

(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,"商品名稱(chēng)不為空","系統(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);//通過(guò)ConnectionDB連接
                                                        try {
                                                                      if(rs.next()){//進(jìn)行判斷集合中是否有數(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);
                            }}
(3)完成效果截圖











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



圖4-4-1購(gòu)買(mǎi)界面布局圖
(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);
              }
}
}
(3)完成效果截圖












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


圖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采用流水布局中間對(duì)齊,然后放置面板,面板采用6行7列網(wǎng)格布局,每一網(wǎng)格再采用流水布局左對(duì)齊,放置標(biāo)簽組件。南邊S流水布局右對(duì)齊,將按鈕jbdelete和jbpay放上。


圖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)完成效果截圖

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




圖4-7-1購(gòu)物車(chē)維護(hù)界面完成布局圖(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)完成效果截圖







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


圖4-8-1購(gòu)物車(chē)修改界面完成布局圖(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)完成效果截圖








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


圖4-9-1充值頁(yè)面完成效果圖(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, "是否確認(rèn)充值?", "系統(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, "此用戶(hù)不存在!","系統(tǒng)消息",JOptionPane.WARNING_MESSAGE);                                                                      }else if(moneyField.getText().equals("")){                                                                                    JOptionPane.showMessageDialog(this, "請(qǐng)輸入充值金額!","系統(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)完成效果截圖 圖4-9-2充值頁(yè)面完成效果圖
5 功能類(lèi)定義——數(shù)據(jù)庫(kù)操作實(shí)現(xiàn)(1)數(shù)據(jù)庫(kù)操作(1)數(shù)據(jù)庫(kù)安裝安裝MySql數(shù)據(jù)庫(kù)(2)導(dǎo)入數(shù)據(jù)              將數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)(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é)通過(guò)這次實(shí)訓(xùn)我的體會(huì)歸納為以下4點(diǎn):1.態(tài)度第一擺正自己的心態(tài),不要以為什么東西上網(wǎng)搜搜就可以了,一定要有自己的東西。只有自己付出過(guò),當(dāng)JAVA購(gòu)物系統(tǒng)程序運(yùn)行成功時(shí)的那種喜悅才會(huì)令自己有一種莫名的自豪感。態(tài)度決定一切!2.興趣是關(guān)鍵我的學(xué)習(xí)完全是興趣導(dǎo)向的。因?yàn)橛信d趣,所以我會(huì)很想充分理解一切細(xì)節(jié)。又因?yàn)槔斫猓栽S多原本片片斷斷的知識(shí)都可以漸漸互相融會(huì)貫通,累積技術(shù)能量,理論和實(shí)務(wù)之間的藩籬被打破了,學(xué)習(xí)效率倍增。學(xué)習(xí)并快樂(lè)著!3.敢于挑戰(zhàn)不安于現(xiàn)成的程序,要敢于用多種方法實(shí)現(xiàn)一個(gè)目的,F(xiàn)在的網(wǎng)絡(luò)科技很發(fā)達(dá),想要一個(gè)源程序的確很簡(jiǎn)單,所以很多人都是在自己都不明白題目要求時(shí),就可以在網(wǎng)上搜到一模一樣的代碼,根本沒(méi)有自己的東西。挑戰(zhàn)自我是項(xiàng)艱巨的任務(wù)。只有堅(jiān)持自己多看代碼多寫(xiě)程序才會(huì)有更多的收獲。4.不懈追求要對(duì)源代碼進(jìn)行不斷地完善,要盡可能地實(shí)現(xiàn)課題所要求的功能。對(duì)初學(xué)者來(lái)說(shuō),大量地寫(xiě)程序是必要的,但過(guò)了某個(gè)階段之后,寫(xiě)程序所帶來(lái)的技術(shù)能力成長(zhǎng)已經(jīng)到了極限,還不如多花一點(diǎn)時(shí)間看書(shū),學(xué)新技術(shù)和新觀念。可以從實(shí)現(xiàn)源程序功能著手,比如添加寫(xiě)模塊啊什么的,實(shí)現(xiàn)更多功能?粗约壕幍某绦蚰艹晒\(yùn)行,這樣自己會(huì)更感興趣,也就會(huì)樂(lè)此不疲


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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