Java-单机版的书店管理系统(练习设计模块和思想_系列 四 )

Posted brucemengbm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java-单机版的书店管理系统(练习设计模块和思想_系列 四 )相关的知识,希望对你有一定的参考价值。

Java-单机版的书店管理系统(练习设计模块和思想_系列 三 ):
http://blog.csdn.net/qq_26525215/article/details/51099202

Java-单机版的书店管理系统(练习设计模块和思想_系列 二 ):
http://blog.csdn.net/qq_26525215/article/details/51089734

Java-单机版的书店管理系统(练习设计模块和思想_系列 一 ):
http://blog.csdn.net/qq_26525215/article/details/51073546

本系列四介绍说明:

主要是加入了Uuid模块,如今的uuid并非由用户输入。而是我们通过软件内部自己主动生成(通过唱票模式),uuid是不会产生反复的!

还有把主界面改了下。以后会改成登录页面的(待完好)。

如今进入其它模块是通过菜单项进入的。

添加了图书模块!

注意:
每一个模块先写哪个。我都是依照先后顺序来上代码的,从前往后依次写代码的。


注意是每一个模块!!。
先写公共类和工具类再写模块的!


我公共类和工具类上传在最后了,你看能够直接在左上角找文件夹跳到那去看。
(限每一个模块内部)(由于还有公共类和工具类等)

软件部分图片:

如今先看软件部分执行图片:
待完毕的主界面:如今通过菜单栏:模块进入其它的模块:
技术分享

用户模块主界面:
技术分享

图书模块主界面:
技术分享

加入用户的界面:
相比上一系列,降低了uuid的输入:
(其它如增删改查的界面全然没有动。这就是设计模块的优点)
技术分享

加入图书的界面:

技术分享

书店管理系统文件文件夹:

技术分享
技术分享
技术分享

主界面代码:

main()方法:BookStore

/*
 * BookStore.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore;

import java.awt.Dimension;
import java.awt.Toolkit;

import cn.hncu.bookStore.book.ui.BookListPanel;
import cn.hncu.bookStore.user.ui.ListPanel;

/**
 *
 * @author  陈浩翔
 */
public class BookStore extends javax.swing.JFrame {

    /** Creates new form BookStore */
    public BookStore() {
        super("书店管理系统---CHX---联系QQ——619699629");
        initComponents();
        //this.setContentPane(new ListPanel(this));
        this.setResizable(false);//不能缩放
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(scr.width / 5, scr.height / 5);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        cutMenuItem = new javax.swing.JMenuItem();
        copyMenuItem = new javax.swing.JMenuItem();
        pasteMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentsMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItemUser = new javax.swing.JMenuItem();
        jMenuItemBook = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 600));

        jButton1.setIcon(new javax.swing.ImageIcon(
                "E:\\百度云同步盘\\MyJavaWork\\myBookStore\\shudian.png")); // NOI18N
        jButton1.setMaximumSize(new java.awt.Dimension(7500, 2300));
        jButton1.setMinimumSize(new java.awt.Dimension(800, 600));

        fileMenu.setText("File");

        openMenuItem.setText("Open");
        fileMenu.add(openMenuItem);

        saveMenuItem.setText("Save");
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setText("Save As ...");
        fileMenu.add(saveAsMenuItem);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText("Edit");

        cutMenuItem.setText("Cut");
        editMenu.add(cutMenuItem);

        copyMenuItem.setText("Copy");
        editMenu.add(copyMenuItem);

        pasteMenuItem.setText("Paste");
        editMenu.add(pasteMenuItem);

        deleteMenuItem.setText("Delete");
        editMenu.add(deleteMenuItem);

        menuBar.add(editMenu);

        helpMenu.setText("Help");

        contentsMenuItem.setText("Contents");
        helpMenu.add(contentsMenuItem);

        aboutMenuItem.setText("About");
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        jMenu1.setForeground(new java.awt.Color(204, 0, 0));
        jMenu1.setText("\u6a21\u5757");

        jMenuItemUser.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
                java.awt.event.KeyEvent.VK_U,
                java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemUser.setFont(new java.awt.Font("Dialog", 1, 14));
        jMenuItemUser.setForeground(new java.awt.Color(0, 204, 0));
        jMenuItemUser.setText("\u7528\u6237");
        jMenuItemUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemUserActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItemUser);

        jMenuItemBook.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
                java.awt.event.KeyEvent.VK_B,
                java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemBook.setFont(new java.awt.Font("Dialog", 1, 14));
        jMenuItemBook.setForeground(new java.awt.Color(0, 204, 51));
        jMenuItemBook.setText("\u56fe\u4e66");
        jMenuItemBook.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemBookActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItemBook);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
                java.awt.event.KeyEvent.VK_DELETE,
                java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setFont(new java.awt.Font("Dialog", 1, 14));
        jMenuItem1.setForeground(new java.awt.Color(0, 204, 0));
        jMenuItem1.setText("\u6ce8\u9500");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        menuBar.add(jMenu1);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
                getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 800,
                Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 600,
                Short.MAX_VALUE));

        pack();
    }// </editor-fold>
    //GEN-END:initComponents

    /**
     * 注销菜单项
     * @param evt
     */
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {

    }

    /**
     * 监听进入图书模块
     * @param evt
     */
    private void jMenuItemBookActionPerformed(java.awt.event.ActionEvent evt) {
        this.setContentPane(new BookListPanel(this));
        this.validate();
    }

    /**
     * 监听进入用户模块
     * @param evt
     */
    private void jMenuItemUserActionPerformed(java.awt.event.ActionEvent evt) {
        this.setContentPane(new ListPanel(this));
        this.validate();

    }

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BookStore().setVisible(true);
            }
        });
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton jButton1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItemBook;
    private javax.swing.JMenuItem jMenuItemUser;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem pasteMenuItem;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    // End of variables declaration//GEN-END:variables

}

图书模块的全部代码和类:

值对象层:

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookModel类:

package cn.hncu.bookStore.book.vo;

import java.io.Serializable;

/**
 * 值对象封装
 * 
 * @author 陈浩翔
 * @version 1.0
 */
public class BookModel implements Serializable{//必须实现这个接口
    private String uuid;//图书ID
    private String name;//图书名字
    private double inPrice;//图书的进价
    private double salePrice;//图书的售价

    /**
     * 
     * @return 图书的ID
     */
    public String getUuid() {
        return uuid;
    }
    /**
     * 
     * @param uuid ---设置图书的ID
     */
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    /**
     * 
     * @return 图书的名字
     */
    public String getName() {
        return name;
    }

    /**
     * 
     * @param name--设置图书的名字
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 
     * @return 得到图书的进价
     */
    public double getInPrice() {
        return inPrice;
    }

    /**
     * 
     * @param inPrice---设置图书的进价
     */
    public void setInPrice(double inPrice) {
        this.inPrice = inPrice;
    }

    /**
     * 
     * @return ---返回图书的售价
     */
    public double getSalePrice() {
        return salePrice;
    }

    /**
     * 
     * @param outPrice---设置图书的售价
     */
    public void setSalePrice(double salePrice) {
        this.salePrice = salePrice;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        BookModel other = (BookModel) obj;
        if (uuid == null) {
            if (other.uuid != null)
                return false;
        } else if (!uuid.equals(other.uuid))
            return false;
        return true;
    }
    @Override
    public String toString() {
        return uuid + ", " + name + ", 进价="
                + inPrice + ", 售价" + salePrice;
    }

}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookQueryModel类:

package cn.hncu.bookStore.book.vo;

public class BookQueryModel extends BookModel{
    private double inPrice2;
    private double salePrice2;
    public double getInPrice2() {
        return inPrice2;
    }
    public void setInPrice2(double inPrice2) {
        this.inPrice2 = inPrice2;
    }
    public double getSalePrice2() {
        return salePrice2;
    }
    public void setSalePrice2(double salePrice2) {
        this.salePrice2 = salePrice2;
    }


}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

数据层:

BookDao接口

package cn.hncu.bookStore.book.dao.dao;

import java.util.List;

import cn.hncu.bookStore.book.vo.BookModel;
import cn.hncu.bookStore.book.vo.BookQueryModel;
/**
 * 
 * @author 陈浩翔
 *
 * @version 1.0
 * 图书模块的数据层接口
 */
public interface BookDao {

    /**
     * 功能:创建一本图书
     * 
     * @param bookModel---将要创建的图书数据
     * @return---true表示创建成功。false表示创建失败
     */
    public boolean create(BookModel book);


    /**
     * 功能:依据图书的唯一标识码uuid删除一本图书
     * 
     * @param uuid---图书唯一的标识码,每本图书都不会同样
     * @return---true表示删除成功,false表示删除失败
     */
    public boolean delete(String uuid);


    /**
     * 功能:改动图书的数据资料
     * 
     * @param user---须要改动的图书数据參数名
     * @return 返回true-表示改动成功了。返回false-表示改动失败
     */
    public boolean update(BookModel book);


    /**
     * 功能:得到全部的图书数据
     * 
     * @return---一个BookModel集合。也就是图书的数据
     */
    public List<BookModel> getAll();


    /**
     * 功能:依照一定的查找条件进行查找,
     * <br/>
     * 把满足查找条件的图书数据返回。
     * 
     * @param bqm---被封装的查找条件
     * @return---满足查找条件的图书数据集合
     */
    public List<BookModel> getbyCondition(BookQueryModel bqm);


    /**
     * 功能:得到一个确定的图书的数据资料
     * 
     * @param uuid---图书唯一标识码
     * @return ---返回按这个唯一标识码找到的图书数据
     */
    public BookModel getSingle(String uuid);

}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookDaoSerImpl类:

package cn.hncu.bookStore.book.dao.impl;

import java.util.ArrayList;
import java.util.List;

import cn.hncu.bookStore.book.dao.dao.BookDao;
import cn.hncu.bookStore.book.vo.BookModel;
import cn.hncu.bookStore.book.vo.BookQueryModel;
import cn.hncu.bookStore.util.FileIoUtil;
/**
 * Dao实现类
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class BookDaoSerImpl implements BookDao {
    private final String FILE_NAME = "Book.txt";

    @Override
    public boolean create(BookModel book) {
        List<BookModel> books = FileIoUtil.readFormFile(FILE_NAME);

        for (BookModel model : books) {
            if (model.getUuid().equals(book.getUuid())) {
                return false;
            }
        }
        books.add(book);
        FileIoUtil.write2file(books, FILE_NAME);
        return true;
    }

    @Override
    public boolean delete(String uuid) {
        List<BookModel> books = FileIoUtil.readFormFile(FILE_NAME);

        for (BookModel model : books) {
            if (model.getUuid().equals(uuid)) {
                books.remove(model);
                FileIoUtil.write2file(books, FILE_NAME);
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean update(BookModel book) {
        List<BookModel> books = FileIoUtil.readFormFile(FILE_NAME);

        for (int i=0;i<books.size();i++) {
            if (books.get(i).getUuid().equals(book.getUuid())) {
                books.set(i, book);
                FileIoUtil.write2file(books, FILE_NAME);
                return true;
            }
        }

        return false;
    }

    @Override
    public List<BookModel> getAll() {
        return FileIoUtil.readFormFile(FILE_NAME);
    }

    @Override
    public List<BookModel> getbyCondition(BookQueryModel bqm) {
        List<BookModel> lists = getAll();
        List<BookModel> results = new ArrayList<BookModel>();

        for(BookModel book: lists){

            if(bqm.getUuid()!=null&&bqm.getUuid().trim().length()>0){
                if(!book.getUuid().equals(bqm.getUuid())){
                    continue;
                }
            }

            if(bqm.getName()!=null&&bqm.getName().trim().length()>0){
                if(book.getName().indexOf(bqm.getName())==-1){
                    continue;
                }
            }

            if(bqm.getInPrice()>0){
                if(book.getInPrice()<bqm.getInPrice()){
                    continue;
                }
            }
            if(bqm.getInPrice2()>0){
                if(book.getInPrice()>bqm.getInPrice2()){
                    continue;
                }
            }

            if(bqm.getSalePrice()>0){
                if(book.getSalePrice()<bqm.getSalePrice()){
                    continue;
                }
            }
            if(bqm.getSalePrice2()>0){
                if(book.getSalePrice()>bqm.getSalePrice2()){
                    continue;
                }
            }

            results.add(book);
        }

        return results;
    }

    @Override
    public BookModel getSingle(String uuid) {
        List<BookModel> list = FileIoUtil.readFormFile(FILE_NAME);
        for(BookModel book:list){
            if(book.getUuid().equals(uuid)){
                return book;
            }
        }
        return null;
    }

}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookDaoFactory类:

package cn.hncu.bookStore.book.dao.factory;

import cn.hncu.bookStore.book.dao.dao.BookDao;
import cn.hncu.bookStore.book.dao.impl.BookDaoSerImpl;
/**
 * 工厂方法
 * new一个实例
 * @author 陈浩翔
 * @version 1.0
 */
public class BookDaoFactory {
    /**
     * 
     * @return BookDao接口的一个实例
     */
    public static BookDao getBookDao(){
        return new BookDaoSerImpl();
    }
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

逻辑层:

BookEbi 接口:

package cn.hncu.bookStore.book.business.ebi;

import java.util.List;

import cn.hncu.bookStore.book.vo.BookModel;
import cn.hncu.bookStore.book.vo.BookQueryModel;

/**
 * 
 * @author 陈浩翔
 *
 * @version 1.0
 * 图书模块的逻辑层接口
 */
public interface BookEbi {

        /**
         * 功能:创建一本图书
         * 
         * @param bookModel---将要创建的图书数据
         * @return---true表示创建成功,false表示创建失败
         */
        public boolean create(BookModel book);


        /**
         * 功能:依据图书的唯一标识码uuid删除一本图书
         * 
         * @param uuid---图书唯一的标识码,每本图书都不会同样
         * @return---true表示删除成功,false表示删除失败
         */
        public boolean delete(String uuid);


        /**
         * 功能:改动图书的数据资料
         * 
         * @param user---须要改动的图书数据參数名
         * @return 返回true-表示改动成功了,返回false-表示改动失败
         */
        public boolean update(BookModel book);


        /**
         * 功能:得到全部的图书数据
         * 
         * @return---一个BookModel集合,也就是图书的数据
         */
        public List<BookModel> getAll();


        /**
         * 功能:依照一定的查找条件进行查找,
         * <br/>
         * 把满足查找条件的图书数据返回。
         * 
         * @param bqm---被封装的查找条件
         * @return---满足查找条件的图书数据集合
         */
        public List<BookModel> getbyCondition(BookQueryModel bqm);


        /**
         * 功能:得到一个确定的图书的数据资料
         * 
         * @param uuid---图书唯一标识码
         * @return ---返回按这个唯一标识码找到的图书数据
         */
        public BookModel getSingle(String uuid);

    }

||||||||||||||||||||||||||||||||||||||||||||||||||

BookEbo 类:

package cn.hncu.bookStore.book.business.ebo;

import java.util.List;

import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.dao.dao.BookDao;
import cn.hncu.bookStore.book.dao.factory.BookDaoFactory;
import cn.hncu.bookStore.book.vo.BookModel;
import cn.hncu.bookStore.book.vo.BookQueryModel;
import cn.hncu.bookStore.common.UuidModelConstance;
import cn.hncu.bookStore.common.uuid.dao.factory.UuidDaoFactory;
import cn.hncu.bookStore.common.uuid.dao.impl.UuidDaoSerImpl;
/**
 * 实现类
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class BookEbo implements BookEbi {
    //注入
    BookDao dao = BookDaoFactory.getBookDao();

    @Override
    public boolean create(BookModel book) {
        //假设表现层中对book对象的数据没有封装完整。那么在这里要为它补全
        //调用uuid模块的dao层来自己主动获取当前book对象的uuid
        String uuid = UuidDaoFactory.getUuidDao().getNextUuid(UuidModelConstance.BOOK);
        book.setUuid(uuid);
        return dao.create(book);
    }

    @Override
    public boolean delete(String uuid) {
        return dao.delete(uuid);
    }

    @Override
    public boolean update(BookModel book) {
        return dao.update(book);
    }

    @Override
    public List<BookModel> getAll() {
        return dao.getAll();
    }

    @Override
    public List<BookModel> getbyCondition(BookQueryModel bqm) {
        return dao.getbyCondition(bqm);
    }

    @Override
    public BookModel getSingle(String uuid) {
        return dao.getSingle(uuid);
    }

}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookEbiFactory 类:

package cn.hncu.bookStore.book.business.factory;

import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.business.ebo.BookEbo;
/**
 * 工厂方法
 *new 一个实例
 * @author 陈浩翔
 * @version 1.0
 */
public class BookEbiFactory {

    public static BookEbi getBookEbi(){
        return new BookEbo();
    }
}

表现层:

BookListPanel 类:图书列表界面

/*
 * BookListPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.book.ui;

import java.util.List;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.book.vo.BookModel;

/**
 *
 * @author  __USER__
 */
public class BookListPanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;

    /** Creates new form BookListPanel */
    public BookListPanel(JFrame mainFrame) {
        this.mainFrame = mainFrame;
        initComponents();
        myInitData();
    }

    public BookListPanel(JFrame mainFrame, List<BookModel> results) {
        this.mainFrame=mainFrame;
        initComponents();
        bookLists.setListData(results.toArray());
    }

    private void myInitData() {
        List<BookModel> lists = BookEbiFactory.getBookEbi().getAll();
        bookLists.setListData(lists.toArray());

    }

    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        bookLists = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        btnToAdd = new javax.swing.JButton();
        btnToDelete = new javax.swing.JButton();
        btnToUpdate = new javax.swing.JButton();
        btnToQuery = new javax.swing.JButton();

        setMinimumSize(new java.awt.Dimension(800, 600));
        setPreferredSize(new java.awt.Dimension(800, 600));
        setLayout(null);

        bookLists.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "" };

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        jScrollPane1.setViewportView(bookLists);

        add(jScrollPane1);
        jScrollPane1.setBounds(170, 80, 480, 230);

        jLabel1.setFont(new java.awt.Font("Dialog", 1, 48));
        jLabel1.setForeground(new java.awt.Color(204, 0, 51));
        jLabel1.setText("\u56fe\u4e66\u5217\u8868");
        add(jLabel1);
        jLabel1.setBounds(300, 0, 260, 80);

        btnToAdd.setFont(new java.awt.Font("Dialog", 1, 24));
        btnToAdd.setForeground(new java.awt.Color(0, 102, 102));
        btnToAdd.setText("\u6dfb\u52a0\u56fe\u4e66");
        btnToAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToAddActionPerformed(evt);
            }
        });
        add(btnToAdd);
        btnToAdd.setBounds(160, 350, 150, 50);

        btnToDelete.setFont(new java.awt.Font("Dialog", 1, 24));
        btnToDelete.setForeground(new java.awt.Color(0, 102, 102));
        btnToDelete.setText("\u5220\u9664\u56fe\u4e66");
        btnToDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToDeleteActionPerformed(evt);
            }
        });
        add(btnToDelete);
        btnToDelete.setBounds(510, 350, 150, 50);

        btnToUpdate.setFont(new java.awt.Font("Dialog", 1, 24));
        btnToUpdate.setForeground(new java.awt.Color(0, 102, 102));
        btnToUpdate.setText("\u4fee\u6539\u56fe\u4e66");
        btnToUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToUpdateActionPerformed(evt);
            }
        });
        add(btnToUpdate);
        btnToUpdate.setBounds(160, 450, 150, 50);

        btnToQuery.setFont(new java.awt.Font("Dialog", 1, 24));
        btnToQuery.setForeground(new java.awt.Color(0, 102, 102));
        btnToQuery.setText("\u67e5\u627e\u56fe\u4e66");
        btnToQuery.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToQueryActionPerformed(evt);
            }
        });
        add(btnToQuery);
        btnToQuery.setBounds(510, 450, 150, 50);
    }// </editor-fold>
    //GEN-END:initComponents

    private void btnToQueryActionPerformed(java.awt.event.ActionEvent evt) {
        mainFrame.setContentPane(new BookQueryPanel(mainFrame));
        mainFrame.validate();
    }

    private void btnToUpdateActionPerformed(java.awt.event.ActionEvent evt) {
        BookModel book = (BookModel) bookLists.getSelectedValue();
        if(book==null){
            JOptionPane.showMessageDialog(mainFrame, "请选择要改动的图书。");
            return ;
        }
        String uuid  = book.getUuid();

        mainFrame.setContentPane(new BookUpdatePanel(mainFrame,uuid));
        mainFrame.validate();


    }

    private void btnToDeleteActionPerformed(java.awt.event.ActionEvent evt) {
        BookModel book = (BookModel) bookLists.getSelectedValue();
        //System.out.println(book);
        if(book==null){
            JOptionPane.showMessageDialog(mainFrame, "请选择要删除的图书!");
            return ;
        }
        String uuid  = book.getUuid();

        mainFrame.setContentPane(new BookDeletePanel(mainFrame,uuid));
        mainFrame.validate();
    }

    private void btnToAddActionPerformed(java.awt.event.ActionEvent evt) {
        mainFrame.setContentPane(new BookAddPanel(mainFrame));
        mainFrame.validate();
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JList bookLists;
    private javax.swing.JButton btnToAdd;
    private javax.swing.JButton btnToDelete;
    private javax.swing.JButton btnToQuery;
    private javax.swing.JButton btnToUpdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookAddPanel 类:加入界面:

/*
 * BookAddPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.book.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.book.vo.BookModel;

/**
 * 
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class BookAddPanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;

    /** Creates new form BookAddPanel 
     * @param mainFrame */
    public BookAddPanel(JFrame mainFrame) {
        this.mainFrame = mainFrame;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfdName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnAdd = new javax.swing.JButton();
        btnBack = new javax.swing.JButton();
        tfdInPrice = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfdSalePrice = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(800, 600));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 48));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("\u6dfb\u52a0\u56fe\u4e66");
        add(jLabel1);
        jLabel1.setBounds(280, 40, 230, 80);

        tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdName.setAutoscrolls(false);
        add(tfdName);
        tfdName.setBounds(280, 170, 150, 30);

        jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel4.setText("\u56fe\u4e66\u540d\u79f0:");
        add(jLabel4);
        jLabel4.setBounds(180, 170, 90, 30);

        btnAdd.setFont(new java.awt.Font("Dialog", 1, 24));
        btnAdd.setForeground(new java.awt.Color(0, 204, 204));
        btnAdd.setText("\u6dfb\u52a0");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        add(btnAdd);
        btnAdd.setBounds(140, 440, 120, 60);

        btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
        btnBack.setForeground(new java.awt.Color(0, 204, 204));
        btnBack.setText("\u8fd4\u56de");
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });
        add(btnBack);
        btnBack.setBounds(520, 440, 120, 60);

        tfdInPrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdInPrice.setAutoscrolls(false);
        add(tfdInPrice);
        tfdInPrice.setBounds(280, 250, 150, 30);

        jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel5.setText("\u8fdb\u8d27\u4ef7\u683c\uff1a");
        add(jLabel5);
        jLabel5.setBounds(180, 250, 90, 30);

        tfdSalePrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdSalePrice.setAutoscrolls(false);
        add(tfdSalePrice);
        tfdSalePrice.setBounds(280, 330, 150, 30);

        jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel6.setText("\u552e\u8d27\u4ef7\u683c\uff1a");
        add(jLabel6);
        jLabel6.setBounds(180, 330, 90, 30);
    }// </editor-fold>
    //GEN-END:initComponents

    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
        back();
    }

    private void back() {
        mainFrame.setContentPane(new BookListPanel(mainFrame));
        mainFrame.validate();
    }

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
        //1收集參数
        String name = tfdName.getText();
        double inPrice = 0;
        double salePrice = 0;
        try {
            inPrice = Double.parseDouble(tfdInPrice.getText());
            salePrice = Double.parseDouble(tfdSalePrice.getText());
        } catch (NumberFormatException e1) {
            JOptionPane.showMessageDialog(mainFrame, "价格的格式错误,请又一次输入。");
            return;
        }


        if (name.equals("") || name.equals(null)) {
            JOptionPane.showMessageDialog(mainFrame, "username为空,请又一次输入!");
            return;
        }

        //2组织參数
        BookModel book = new BookModel();
        book.setName(name);
        book.setInPrice(inPrice);
        book.setSalePrice(salePrice);

        //3调用逻辑层
        BookEbi ebi = BookEbiFactory.getBookEbi();

        //4依据调用返回结果导向不同页面
        if (ebi.create(book)) {
            back();
        } else {
            JOptionPane.showMessageDialog(null, "该图书已经存在!");
        }
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnBack;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField tfdInPrice;
    private javax.swing.JTextField tfdName;
    private javax.swing.JTextField tfdSalePrice;
    // End of variables declaration//GEN-END:variables

}

||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookDeletePanel 类:删除界面:

/*
 * BookDeletePanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.book.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.book.vo.BookModel;

/**
 * 
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class BookDeletePanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;
    private String uuid = null;

    /** Creates new form BookDeletePanel 
     * @param mainFrame 
     * @param uuid */
    public BookDeletePanel(JFrame mainFrame, String uuid) {
        this.mainFrame = mainFrame;
        this.uuid = uuid;
        initComponents();
        myInitData();
    }

    private void myInitData() {
        BookModel book = BookEbiFactory.getBookEbi().getSingle(uuid);
        //System.out.println(book);
        tfdName.setText(book.getName());
        tfdName.setEditable(false);

        tfdUuid.setText(book.getUuid());
        tfdUuid.setEditable(false);

        tfdInPrice.setText(String.valueOf(book.getInPrice()));
        tfdInPrice.setEditable(false);

        tfdSalePrice.setText(String.valueOf(book.getSalePrice()));
        tfdSalePrice.setEditable(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfdName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfdUuid = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnDelete = new javax.swing.JButton();
        btnBack = new javax.swing.JButton();
        tfdInPrice = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfdSalePrice = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(800, 600));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 48));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("\u5220\u9664\u56fe\u4e66");
        add(jLabel1);
        jLabel1.setBounds(280, 40, 230, 80);

        tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdName.setAutoscrolls(false);
        add(tfdName);
        tfdName.setBounds(480, 190, 150, 30);

        jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel3.setText("uuid:");
        add(jLabel3);
        jLabel3.setBounds(130, 190, 50, 30);

        tfdUuid.setFont(new java.awt.Font("Dialog", 1, 12));
        add(tfdUuid);
        tfdUuid.setBounds(200, 190, 110, 30);

        jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel4.setText("\u56fe\u4e66\u540d\u79f0:");
        add(jLabel4);
        jLabel4.setBounds(380, 190, 90, 30);

        btnDelete.setFont(new java.awt.Font("Dialog", 1, 24));
        btnDelete.setForeground(new java.awt.Color(0, 204, 204));
        btnDelete.setText("\u5220\u9664");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });
        add(btnDelete);
        btnDelete.setBounds(140, 440, 120, 60);

        btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
        btnBack.setForeground(new java.awt.Color(0, 204, 204));
        btnBack.setText("\u8fd4\u56de");
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });
        add(btnBack);
        btnBack.setBounds(520, 440, 120, 60);

        tfdInPrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdInPrice.setAutoscrolls(false);
        add(tfdInPrice);
        tfdInPrice.setBounds(200, 300, 150, 30);

        jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel5.setText("\u8fdb\u8d27\u4ef7\u683c\uff1a");
        add(jLabel5);
        jLabel5.setBounds(100, 300, 90, 30);

        tfdSalePrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdSalePrice.setAutoscrolls(false);
        add(tfdSalePrice);
        tfdSalePrice.setBounds(480, 300, 150, 30);

        jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel6.setText("\u552e\u8d27\u4ef7\u683c\uff1a");
        add(jLabel6);
        jLabel6.setBounds(380, 300, 90, 30);
    }// </editor-fold>
    //GEN-END:initComponents

    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
        back();
    }

    private void back() {
        mainFrame.setContentPane(new BookListPanel(mainFrame));
        mainFrame.validate();
    }

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
        //1收集參数
        //2组织參数
        //3调用逻辑层

        //4依据调用返回结果导向不同页面
        boolean isFlag = BookEbiFactory.getBookEbi().delete(uuid);
        if (isFlag) {
            back();
        } else {
            JOptionPane.showMessageDialog(null, "该图书已经不存在!");
        }
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton btnBack;
    private javax.swing.JButton btnDelete;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField tfdInPrice;
    private javax.swing.JTextField tfdName;
    private javax.swing.JTextField tfdSalePrice;
    private javax.swing.JTextField tfdUuid;
    // End of variables declaration//GEN-END:variables

}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookQueryPanel 类:查询界面:

/*
 * BookQueryPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.book.ui;

import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.book.vo.BookModel;
import cn.hncu.bookStore.book.vo.BookQueryModel;

/**
 * 
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class BookQueryPanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;

    /** Creates new form BookQueryPanel 
     * @param mainFrame */
    public BookQueryPanel(JFrame mainFrame) {
        this.mainFrame = mainFrame;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfdName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfdUuid = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnQuery = new javax.swing.JButton();
        btnBack = new javax.swing.JButton();
        tfdInPrice = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfdSalePrice = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tfdInPrice2 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        tfdSalePrice2 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(800, 600));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 48));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("\u67e5\u627e\u56fe\u4e66");
        add(jLabel1);
        jLabel1.setBounds(280, 40, 230, 80);

        tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdName.setAutoscrolls(false);
        add(tfdName);
        tfdName.setBounds(520, 190, 150, 30);

        jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel3.setText("uuid:");
        add(jLabel3);
        jLabel3.setBounds(130, 190, 50, 30);

        tfdUuid.setFont(new java.awt.Font("Dialog", 1, 12));
        add(tfdUuid);
        tfdUuid.setBounds(200, 190, 150, 30);

        jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel4.setText("\u56fe\u4e66\u540d\u79f0:");
        add(jLabel4);
        jLabel4.setBounds(420, 190, 90, 30);

        btnQuery.setFont(new java.awt.Font("Dialog", 1, 24));
        btnQuery.setForeground(new java.awt.Color(0, 204, 204));
        btnQuery.setText("\u67e5\u627e");
        btnQuery.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQueryActionPerformed(evt);
            }
        });
        add(btnQuery);
        btnQuery.setBounds(140, 470, 120, 60);

        btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
        btnBack.setForeground(new java.awt.Color(0, 204, 204));
        btnBack.setText("\u8fd4\u56de");
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });
        add(btnBack);
        btnBack.setBounds(490, 470, 120, 60);

        tfdInPrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdInPrice.setAutoscrolls(false);
        add(tfdInPrice);
        tfdInPrice.setBounds(200, 280, 150, 30);

        jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel5.setText("\u8fdb\u8d27\u6700\u4f4e\u4ef7\u683c\uff1a");
        add(jLabel5);
        jLabel5.setBounds(60, 280, 130, 30);

        tfdSalePrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdSalePrice.setAutoscrolls(false);
        add(tfdSalePrice);
        tfdSalePrice.setBounds(200, 370, 150, 30);

        jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel6.setText("\u552e\u8d27\u6700\u4f4e\u4ef7\u683c\uff1a");
        add(jLabel6);
        jLabel6.setBounds(60, 370, 130, 30);

        tfdInPrice2.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdInPrice2.setAutoscrolls(false);
        add(tfdInPrice2);
        tfdInPrice2.setBounds(520, 280, 150, 30);

        jLabel11.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel11.setText("\u8fdb\u8d27\u6700\u9ad8\u4ef7\u683c\uff1a");
        add(jLabel11);
        jLabel11.setBounds(380, 280, 130, 30);

        tfdSalePrice2.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdSalePrice2.setAutoscrolls(false);
        add(tfdSalePrice2);
        tfdSalePrice2.setBounds(520, 370, 150, 30);

        jLabel12.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel12.setText("\u552e\u8d27\u6700\u9ad8\u4ef7\u683c\uff1a");
        add(jLabel12);
        jLabel12.setBounds(380, 370, 130, 30);
    }// </editor-fold>
    //GEN-END:initComponents

    protected void btnQueryActionPerformed(ActionEvent evt) {
        //1收集參数
        String uuid = tfdUuid.getText();
        String name = tfdName.getText();
        double inPrice = 0;
        double inPrice2 = 0;
        double salePrice = 0;
        double salePrice2 = 0;

        if (tfdInPrice.getText() != null
                && tfdInPrice.getText().trim().length() > 0) {
            try {
                inPrice = Double.parseDouble(tfdInPrice.getText());
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(mainFrame, "最低进价输入格式错误!");
                return;
            }
        }

        if (tfdInPrice2.getText() != null
                && tfdInPrice2.getText().trim().length() > 0) {
            try {
                inPrice2 = Double.parseDouble(tfdInPrice2.getText());
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(mainFrame, "最高进价输入格式错误!");
                return;
            }
        }

        if (tfdSalePrice.getText() != null
                && tfdSalePrice.getText().trim().length() > 0) {
            try {
                salePrice = Double.parseDouble(tfdSalePrice.getText());
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(mainFrame, "最低进价输入格式错误!");
                return;
            }
        }

        if (tfdSalePrice2.getText() != null
                && tfdSalePrice2.getText().trim().length() > 0) {
            try {
                salePrice2 = Double.parseDouble(tfdSalePrice2.getText());
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(mainFrame, "最低进价输入格式错误!");
                return;
            }
        }
        //2组织參数
        BookQueryModel bqm = new BookQueryModel();
        bqm.setUuid(uuid);
        bqm.setName(name);
        bqm.setInPrice(inPrice);
        bqm.setInPrice2(inPrice2);
        bqm.setSalePrice(salePrice);
        bqm.setSalePrice2(salePrice2);

        //3调用逻辑层
        BookEbi ebi = BookEbiFactory.getBookEbi();
        List<BookModel> results = ebi.getbyCondition(bqm);

        //4依据调用返回结果导向不同页面
        mainFrame.setContentPane(new BookListPanel(mainFrame, results));
        mainFrame.validate();

    }

    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
        back();
    }

    private void back() {
        mainFrame.setContentPane(new BookListPanel(mainFrame));
        mainFrame.validate();
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton btnBack;
    private javax.swing.JButton btnQuery;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField tfdInPrice;
    private javax.swing.JTextField tfdInPrice2;
    private javax.swing.JTextField tfdName;
    private javax.swing.JTextField tfdSalePrice;
    private javax.swing.JTextField tfdSalePrice2;
    private javax.swing.JTextField tfdUuid;
    // End of variables declaration//GEN-END:variables

}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||

BookUpdatePanel类:改动界面:

/*
 * BookUpdatePanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.book.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.book.vo.BookModel;

/**
 * 
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class BookUpdatePanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;
    private String uuid = null;

    /** Creates new form BookUpdatePanel 
     * @param uuid 
     * @param mainFrame */
    public BookUpdatePanel(JFrame mainFrame, String uuid) {
        this.mainFrame = mainFrame;
        this.uuid = uuid;
        initComponents();
        myInitData();
    }

    private void myInitData() {
        BookModel book = BookEbiFactory.getBookEbi().getSingle(uuid);

        tfdUuid.setText(uuid);
        tfdUuid.setEditable(false);

        tfdName.setText(book.getName());
        tfdInPrice.setText(String.valueOf(book.getInPrice()));
        tfdSalePrice.setText(String.valueOf(book.getSalePrice()));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //GEN-BEGIN:initComponents
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfdName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfdUuid = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnUpdata = new javax.swing.JButton();
        btnBack = new javax.swing.JButton();
        tfdInPrice = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfdSalePrice = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(800, 600));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 48));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("\u4fee\u6539\u56fe\u4e66");
        add(jLabel1);
        jLabel1.setBounds(280, 40, 230, 80);

        tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdName.setAutoscrolls(false);
        add(tfdName);
        tfdName.setBounds(480, 190, 150, 30);

        jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel3.setText("uuid:");
        add(jLabel3);
        jLabel3.setBounds(130, 190, 50, 30);

        tfdUuid.setFont(new java.awt.Font("Dialog", 1, 12));
        add(tfdUuid);
        tfdUuid.setBounds(200, 190, 110, 30);

        jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel4.setText("\u56fe\u4e66\u540d\u79f0:");
        add(jLabel4);
        jLabel4.setBounds(380, 190, 90, 30);

        btnUpdata.setFont(new java.awt.Font("Dialog", 1, 24));
        btnUpdata.setForeground(new java.awt.Color(0, 204, 204));
        btnUpdata.setText("\u4fee\u6539");
        btnUpdata.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdataActionPerformed(evt);
            }
        });
        add(btnUpdata);
        btnUpdata.setBounds(140, 440, 120, 60);

        btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
        btnBack.setForeground(new java.awt.Color(0, 204, 204));
        btnBack.setText("\u8fd4\u56de");
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });
        add(btnBack);
        btnBack.setBounds(520, 440, 120, 60);

        tfdInPrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdInPrice.setAutoscrolls(false);
        add(tfdInPrice);
        tfdInPrice.setBounds(200, 300, 150, 30);

        jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel5.setText("\u8fdb\u8d27\u4ef7\u683c\uff1a");
        add(jLabel5);
        jLabel5.setBounds(100, 300, 90, 30);

        tfdSalePrice.setFont(new java.awt.Font("Dialog", 1, 18));
        tfdSalePrice.setAutoscrolls(false);
        add(tfdSalePrice);
        tfdSalePrice.setBounds(480, 300, 150, 30);

        jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel6.setText("\u552e\u8d27\u4ef7\u683c\uff1a");
        add(jLabel6);
        jLabel6.setBounds(380, 300, 90, 30);
    }// </editor-fold>
    //GEN-END:initComponents

    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
        back();
    }

    private void back() {
        mainFrame.setContentPane(new BookListPanel(mainFrame));
        mainFrame.validate();
    }

    private void btnUpdataActionPerformed(java.awt.event.ActionEvent evt) {
        //1收集參数
        String name = tfdName.getText();
        double inPrice = 0;
        double salePrice = 0;
        try {
            inPrice = Double.parseDouble(tfdInPrice.getText());
            salePrice = Double.parseDouble(tfdSalePrice.getText());
        } catch (NumberFormatException e1) {
            JOptionPane.showMessageDialog(mainFrame, "价格的格式错误,请又一次输入!");
            return;
        }

        if (name.equals("") || name.equals(null)) {
            JOptionPane.showMessageDialog(mainFrame, "username为空,请又一次输入!");
            return;
        }

        //2组织參数
        BookModel book = new BookModel();
        book.setName(name);
        book.setUuid(uuid);
        book.setInPrice(inPrice);
        book.setSalePrice(salePrice);

        //3调用逻辑层
        BookEbi ebi = BookEbiFactory.getBookEbi();

        //4依据调用返回结果导向不同页面
        if (ebi.update(book)) {
            back();
        } else {
            JOptionPane.showMessageDialog(null, "该图书已经存在!");
        }
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton btnBack;
    private javax.swing.JButton btnUpdata;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField tfdInPrice;
    private javax.swing.JTextField tfdName;
    private javax.swing.JTextField tfdSalePrice;
    private javax.swing.JTextField tfdUuid;
    // End of variables declaration//GEN-END:variables

}

工具类:

FileIoUtil 类:数据读取:

package cn.hncu.bookStore.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 * 用户的公用数据读取写入类
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class FileIoUtil {

    public FileIoUtil() {
    }


    /**
     *  从数据库中读取全部的数据并返回出来
     *  
     * @param fileName:(数据表相应的文件名称字)
     * @return 全部表的记录。
     */
    @SuppressWarnings("unchecked")//压警告
    public static<E> List<E> readFormFile(String fileName){
        List<E> list = new ArrayList<E>();
        final File file = new File(fileName);

        ObjectInputStream in =null;
        if(!file.exists()){
            //JOptionPane.showMessageDialog(null, "数据表不存在!");
            return list;
        }
        try {
            in = new ObjectInputStream(new FileInputStream(fileName));
            try {
                list = (List<E>) in.readObject();

            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(in!=null){
                try {
                    in.close();
                } catch (IOException e) {
                    throw new RuntimeException("数据库关闭失败");
                }
            }
        }
        return list;
    }


    /**
     * 写入一个list集合进入数据文件fileName
     * 
     * @param list(须要存储的数据集合)
     * @param fileName(写入到哪个文件的文件名称字)
     */
    public static<E> void write2file(List<E> list, String fileName){
        ObjectOutputStream out = null;

        try {
            out = new ObjectOutputStream(new FileOutputStream(fileName));
            out.writeObject(list);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(out!=null){
                try {
                    out.close();
                } catch (IOException e) {
                    throw new RuntimeException("数据库关闭失败!");
                }
            }
        }
    }

}

最后说明:

由于感觉实在是太长了。我系列四又分了2个小模块。


还有Uuid模块和用户模块和公共类,我会在Java-单机版的书店管理系统(练习设计模块和思想_系列 四(2) )贴出全部代码。



















以上是关于Java-单机版的书店管理系统(练习设计模块和思想_系列 四 )的主要内容,如果未能解决你的问题,请参考以下文章

Java之------单机版书店管理系统(设计思想和设计模式系列三)工具包和公共包

Java-单机版的书店管理系统(系列 一 )

Java项目:在线书城书店系统(java+jdbc+Servlet+mysql)

网上书店信息管理系统--基于Mysql数据库与java

网上书店管理系统项目Java数据库编程实战

《深入理解Android内核设计思想》已陆续在全国各大书店及网上书店上市,感谢大家一直以来的支持~~