欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java設(shè)計模塊系列之書店管理系統(tǒng)單機版(二)

 更新時間:2016年08月22日 15:46:16   作者:qq_26525215  
這篇文章主要為大家詳細介紹了Java單機版的書店管理系統(tǒng)設(shè)計模塊和思想第二章,感興趣的小伙伴們可以參考一下

Java-單機版的書店管理系統(tǒng)(練習(xí)設(shè)計模塊和思想_系列 一 ): http://www.dbjr.com.cn/article/91004.htm

介紹

小提示:上面一點有一個目錄,可以快速定位到自己需要看的類。
今天對前面的代碼有了小小的修改,讓代碼更加完善了一點。
至于用戶唯一標(biāo)識碼uuid,會在以后修改成程序內(nèi)部生成的,
現(xiàn)在的uuid還是由用戶自己設(shè)置。

今天對這個程序,添加了用戶界面的表現(xiàn)層的一部分,增加了公共類 枚舉,
下面貼出目前我寫的這個程序的全部代碼:我會逐漸的寫完這個程序的,請大家放心?。ㄐ枰獙崿F(xiàn)的功能在這個書店管理系統(tǒng)的系列一可以找到,我為這個系列的文章已經(jīng)分類了,方便大家尋找)
這個系列的博客是不會斷的。

現(xiàn)在的代碼分層:

現(xiàn)在的程序運行后的圖片:

我按照從目錄上面到下面的順序貼出代碼:
請注意!這個代碼順序并不是我寫代碼的順序!
如果你們要參考我的寫,請不要按照我貼的代碼的順序。
應(yīng)該先寫公共類,工具類。
再次:數(shù)據(jù)層類—>邏輯層類—>表現(xiàn)層類
現(xiàn)在程序運行后的部分圖片:

 

UserTypeEnum類:

cn.hncu.bookStore.common;
UserTypeEnum類:

package cn.hncu.bookStore.common;

/**
 * 功能:用戶類型的枚舉!<br/>
 * 定義在公共模塊。<br/>
 * 變量:<br/>
 * ADMIN(1,"超級管理員"),<br/>
 * BOOK(2,"圖書管理員"),<br/>
 * IN(3,"進貨管理員"),<br/>
 * OUT(4,"銷售管理員"),<br/>
 * STOCK(5,"庫存管理員");<br/>
 * @author chx
 * @version 1.0
 */
public enum UserTypeEnum {
 ADMIN(1,"超級管理員"),
 BOOK(2,"圖書管理員"),
 IN(3,"進貨管理員"),
 OUT(4,"銷售管理員"),
 STOCK(5,"庫存管理員");

 private final int type;
 private final String name;

 /**
  * 初始化枚舉變量名字
  * @param type---枚舉變量對應(yīng)的整型數(shù)字
  * @param name---枚舉變量對應(yīng)的String型名字
  */
 private UserTypeEnum(int type, String name) {
  this.type=type;
  this.name=name;
 }

 /**
  * 得到當(dāng)前枚舉變量的數(shù)字
  * @return---type-編號
  */
 public int getType() {
  return type;
 }

 /**
  * 得到當(dāng)前枚舉變量的中文名字
  * @return---name-中文名字
  */
 public String getName() {
  return name;
 }

 /**
  * 根據(jù)枚舉變量的int數(shù)字得到數(shù)字對應(yīng)的枚舉變量的中文名字
  * @param type---需要傳入的int型參數(shù)
  * @return ---如果存在這樣的數(shù)字對應(yīng)的枚舉變量,就返回這個枚舉變量的中文名字。
  * <br/>---如果不存在這樣的數(shù)字對應(yīng)的枚舉變量,就拋出一個異常信息。
  */
 public static String getNameByType(int type){
  for(UserTypeEnum userType:UserTypeEnum.values()){
   if(userType.getType()==type){
    return userType.getName();
   }
  }
  throw new IllegalArgumentException("枚舉中沒有對應(yīng)的用戶類型:"+type);
 }

 /**
  * 根據(jù)枚舉變量的name中文名字得到name對應(yīng)的枚舉變量的int型type
  * @param name---需要傳入的String型名字
  * @return ---如果存在這樣的名字對應(yīng)的枚舉變量,就返回這個枚舉變量對應(yīng)的type-int
  * <br/> ---如果不存在這樣的名字對應(yīng)的枚舉變量,就拋出一個異常信息
  */ 
 public static int getTypeByName(String name){
  for(UserTypeEnum userType:UserTypeEnum.values()){
   if(userType.getName().equals(name)){
    return userType.getType();
   }
  }
  throw new IllegalArgumentException("枚舉中沒有對應(yīng)的用戶類型:"+name);
 }
}


 UserEbi接口:

cn.hncu.bookStore.user.business.ebi;
UserEbi接口:

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

import java.util.List;

import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
/**
 * 邏輯層的接口
 *
 * @author chx
 * @version 1.0
 */
public interface UserEbi {

 /**
  * 功能:創(chuàng)建一個用戶
  * 
  * @param userModel---將要創(chuàng)建的用戶數(shù)據(jù)
  * @return---true表示創(chuàng)建成功,false表示創(chuàng)建失敗
  */
 public boolean create(UserModel user);

 /**
  * 功能:根據(jù)用戶的唯一標(biāo)識碼uuid刪除一個用戶
  * 
  * @param uuid---用戶唯一的標(biāo)識碼,每個用戶都不會相同
  * @return---true表示刪除成功,false表示刪除失敗
  */
 public boolean delete(String uuid);

 /**
  * 功能:修改用戶的數(shù)據(jù)資料
  * 
  * @param user---需要修改的用戶數(shù)據(jù)參數(shù)名
  * @return 返回true-表示修改成功了,返回false-表示修改失敗
  */
 public boolean update(UserModel user);

 /**
  * 功能:得到所有的用戶數(shù)據(jù)
  * 
  * @return---一個UserModel集合,也就是用戶的數(shù)據(jù)
  */
 public List<UserModel> getAll();

 /**
  * 功能:按照一定的查找條件進行查找,
  * <br/>
  * 把滿足查找條件的用戶數(shù)據(jù)返回。
  * 
  * @param uqm---被封裝的查找條件
  * @return---滿足查找條件的用戶數(shù)據(jù)集合
  */
 public List<UserModel> getbyCondition(UserQueryModel uqm);

 /**
  * 功能:得到一個確定的用戶的數(shù)據(jù)資料
  * 
  * @param uuid---用戶唯一標(biāo)識碼
  * @return ---返回按這個唯一標(biāo)識碼找到的用戶數(shù)據(jù)
  */
 public UserModel getSingle(String uuid);
}


 UserEbo類:

cn.hncu.bookStore.user.business.ebo;
UserEbo類:

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

import java.util.List;

import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.dao.dao.UserDao;
import cn.hncu.bookStore.user.dao.factory.UserDaoFactory;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;

public class UserEbo implements UserEbi{
 private UserDao dao = UserDaoFactory.getUserDao();

 @Override
 public boolean create(UserModel user) {
  return dao.create(user);
 }

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

 @Override
 public boolean update(UserModel user) {
  return dao.update(user);
 }

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

 @Override
 public List<UserModel> getbyCondition(UserQueryModel uqm) {
  // TODO Auto-generated method stub
  return null;
 }

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


 UserEbiFactory類:

 cn.hncu.bookStore.user.business.factory;
UserEbiFactory類:

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

import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.ebo.UserEbo;

public class UserEbiFactory {
 public static UserEbi getUserEbi(){
  return new UserEbo();
 }
}


 UserDao接口:

cn.hncu.bookStore.user.dao.dao;
UserDao接口:

package cn.hncu.bookStore.user.dao.dao;

import java.util.List;

import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;

/**
 * 
 * @author 陳浩翔
 *
 * @version 1.0
 * 用戶模塊的數(shù)據(jù)層接口
 */
public interface UserDao {
 /**
  * 功能:創(chuàng)建一個用戶
  * 
  * @param userModel---將要創(chuàng)建的用戶數(shù)據(jù)
  * @return---true表示創(chuàng)建成功,false表示創(chuàng)建失敗
  */
 public boolean create(UserModel user);

 /**
  * 功能:根據(jù)用戶的唯一標(biāo)識碼uuid刪除一個用戶
  * 
  * @param uuid---用戶唯一的標(biāo)識碼,每個用戶都不會相同
  * @return---true表示刪除成功,false表示刪除失敗
  */
 public boolean delete(String uuid);

 /**
  * 功能:修改用戶的數(shù)據(jù)資料
  * 
  * @param user---需要修改的用戶數(shù)據(jù)參數(shù)名
  * @return 返回true-表示修改成功了,返回false-表示修改失敗
  */
 public boolean update(UserModel user);

 /**
  * 功能:得到所有的用戶數(shù)據(jù)
  * 
  * @return---一個UserModel集合,也就是用戶的數(shù)據(jù)
  */
 public List<UserModel> getAll();

 /**
  * 功能:按照一定的查找條件進行查找,
  * <br/>
  * 把滿足查找條件的用戶數(shù)據(jù)返回。
  * 
  * @param uqm---被封裝的查找條件
  * @return---滿足查找條件的用戶數(shù)據(jù)集合
  */
 public List<UserModel> getbyCondition(UserQueryModel uqm);

 /**
  * 功能:得到一個確定的用戶的數(shù)據(jù)資料
  * 
  * @param uuid---用戶唯一標(biāo)識碼
  * @return ---返回按這個唯一標(biāo)識碼找到的用戶數(shù)據(jù)
  */
 public UserModel getSingle(String uuid);

}


 UserDaoFactory類:

cn.hncu.bookStore.user.dao.factory;
UserDaoFactory類:

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

import cn.hncu.bookStore.user.dao.dao.UserDao;
import cn.hncu.bookStore.user.dao.impl.UserDaoSerImpl;
/**
 * 工廠方法<br/>
 * new 一個dao的實例
 * @author 陳浩翔
 *
 * @version 1.0
 * 
 */
public class UserDaoFactory {
 public static UserDao getUserDao(){
  return new UserDaoSerImpl();
 }
}


 UserDaoSerImpl類:

cn.hncu.bookStore.user.dao.impl;
UserDaoSerImpl類:

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

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

import cn.hncu.bookStore.user.dao.dao.UserDao;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
import cn.hncu.bookStore.util.FileIoUtil;

/**
 * <br/>
 * 對用戶數(shù)據(jù)處理的具體實現(xiàn)類 ----實現(xiàn)了UserDao接口
 * 
 * @author 陳浩翔
 * 
 * @version 1.0
 */
public class UserDaoSerImpl implements UserDao {

 private static final String FILE_NAME = "User.txt";

 @Override
 public boolean create(UserModel user) {
  // 1先把已有的數(shù)據(jù)反序列化(讀)出來
  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);
  // 2判斷該用戶是否已經(jīng)存在,再決定是否創(chuàng)建
  for (UserModel userModel : list) {
   // 如果2個用戶的uuid相等,用戶就是相同的
   if (userModel.getUuid().equals(user.getUuid())) {
    return false;// 用戶已經(jīng)存在了,返回false
   }
  }
  // 3如果用戶不存在,就創(chuàng)建
  list.add(user);
  FileIoUtil.write2file(list, FILE_NAME);
  return true;// 創(chuàng)建成功,返回true
 }

 @Override
 public boolean delete(String uuid) {

  // 1先把已有的數(shù)據(jù)反序列化(讀)出來
  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);

  // 2判斷該用戶是否已經(jīng)存在,再決定是否刪除

  // for(int i=0;i<list.size();i++){
  // if(list.get(i).getUuid().equals(uuid)){
  // list.remove(i);
  // FileIoUtil.write2file(list, FILE_NAME);
  // return true;
  // }
  // }

  for (UserModel userModel : list) {
   // 如果2個用戶的uuid相等,用戶就是相同的
   if (userModel.getUuid().equals(uuid)) {
    list.remove(userModel);
    FileIoUtil.write2file(list, FILE_NAME);
    // 刪除成功,返回true
    return true;
   }
  }
  // 3用戶不存在
  // 刪除失敗,返回false
  return false;
 }

 @Override
 public boolean update(UserModel user) {
  // 1先把已有的數(shù)據(jù)反序列化(讀)出來
  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);

  // 2判斷該用戶是否已經(jīng)存在,再決定是否創(chuàng)建
  for (int i = 0; i < list.size(); i++) {
   // uuid是不能改的,通過uuid來找到那個用戶數(shù)據(jù),再修改就ok了
   if (list.get(i).getUuid().equals(user.getUuid())) {
    // 將找到的用戶修改成user
    list.set(i, user);
    FileIoUtil.write2file(list, FILE_NAME);
    // 找到用戶,返回true
    return true;
   }
  }
  // 3若該用戶不存在,則修改失敗
  return false;
 }

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

 @Override
 public List<UserModel> getbyCondition(UserQueryModel uqm) {
  // TODO Auto-generated method stub
  return null;
 }

 @Override
 public UserModel getSingle(String uuid) {
  // 1先把已有的數(shù)據(jù)反序列化(讀)出來
  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);

  // 2判斷該用戶是否已經(jīng)存在,存在就返回那個用戶
  for (int i = 0; i < list.size(); i++) {
   if (list.get(i).getUuid().equals(uuid)) {
    return list.get(i);
   }
  }

  // 3若該用戶不存在,返回null
  return null;
 }

}


 AddPanel類:

cn.hncu.bookStore.user.ui;
AddPanel類:

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

package cn.hncu.bookStore.user.ui;

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

import cn.hncu.bookStore.common.UserTypeEnum;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.util.FileIoUtil;

/**
 *
 * @author 陳浩翔
 */
public class AddPanel extends javax.swing.JPanel {

 private JFrame mainFrame = null;

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

 private void myInitData() {
  for (UserTypeEnum type : UserTypeEnum.values()) {
   combType.addItem(type.getName());
  }
 }

 /** 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();
  jLabel2 = new javax.swing.JLabel();
  tfdName = new javax.swing.JTextField();
  jLabel3 = new javax.swing.JLabel();
  tfdUuid = new javax.swing.JTextField();
  jLabel4 = new javax.swing.JLabel();
  tfdPwd2 = new javax.swing.JPasswordField();
  jLabel5 = new javax.swing.JLabel();
  jLabel6 = new javax.swing.JLabel();
  combType = new javax.swing.JComboBox();
  tfdPwd = new javax.swing.JPasswordField();
  btnAdd = new javax.swing.JButton();
  btnBack = new javax.swing.JButton();

  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\u7528\u6237");
  add(jLabel1);
  jLabel1.setBounds(270, 30, 230, 80);

  jLabel2.setFont(new java.awt.Font("微軟雅黑", 0, 18));
  jLabel2.setText("\u7528\u6237\u7c7b\u578b:");
  add(jLabel2);
  jLabel2.setBounds(40, 310, 90, 30);

  tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
  tfdName.setAutoscrolls(false);
  add(tfdName);
  tfdName.setBounds(420, 160, 120, 30);

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

  tfdUuid.setFont(new java.awt.Font("Dialog", 0, 11));
  add(tfdUuid);
  tfdUuid.setBounds(140, 160, 110, 30);

  jLabel4.setFont(new java.awt.Font("微軟雅黑", 0, 18));
  jLabel4.setText("\u59d3\u540d:");
  add(jLabel4);
  jLabel4.setBounds(360, 160, 50, 30);
  add(tfdPwd2);
  tfdPwd2.setBounds(420, 240, 170, 30);

  jLabel5.setFont(new java.awt.Font("微軟雅黑", 0, 18));
  jLabel5.setText("\u5bc6\u7801:");
  add(jLabel5);
  jLabel5.setBounds(70, 240, 50, 30);

  jLabel6.setFont(new java.awt.Font("微軟雅黑", 0, 18));
  jLabel6.setText("\u786e\u8ba4\u5bc6\u7801:");
  add(jLabel6);
  jLabel6.setBounds(330, 240, 90, 30);

  combType.setFont(new java.awt.Font("Dialog", 1, 18));
  combType.setForeground(new java.awt.Color(51, 51, 255));
  combType.setModel(new javax.swing.DefaultComboBoxModel(
    new String[] { "請選擇..." }));
  add(combType);
  combType.setBounds(140, 310, 160, 30);

  tfdPwd.setFont(new java.awt.Font("宋體", 1, 18));
  add(tfdPwd);
  tfdPwd.setBounds(140, 240, 160, 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, 430, 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(470, 430, 120, 60);
 }// </editor-fold>
 //GEN-END:initComponents

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

 /**
  *監(jiān)聽返回按鈕
  * @param 返回按鈕的點擊監(jiān)聽
  */
 private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
  back();
 }

 private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
  //1收集參數(shù)
  String uuid = tfdUuid.getText();
  String name = tfdName.getText();
  String pwd = new String(tfdPwd.getPassword());
  String pwd2 = new String(tfdPwd2.getPassword());

  if (!pwd.equals(pwd2)) {
   JOptionPane.showMessageDialog(null, "兩次密碼輸入不一致,請重新輸入!");
   return;
  }
  int type = 0;

  try {
   type = UserTypeEnum.getTypeByName(combType.getSelectedItem()
     .toString());
  } catch (Exception e) {
   JOptionPane.showMessageDialog(null, "請指定用戶類型!");
   return;
  }

  //2組織參數(shù)
  UserModel user = new UserModel();
  user.setName(name);
  user.setPwd(pwd);
  user.setType(type);
  user.setUuid(uuid);

  //3調(diào)用邏輯層
  UserEbi ebi = UserEbiFactory.getUserEbi();

  //4根據(jù)調(diào)用返回結(jié)果導(dǎo)向不同頁面
  if (ebi.create(user)) {
   back();
  } else {
   JOptionPane.showMessageDialog(null, "該用戶已經(jīng)存在!");
  }
 }

 //GEN-BEGIN:variables
 // Variables declaration - do not modify
 private javax.swing.JButton btnAdd;
 private javax.swing.JButton btnBack;
 private javax.swing.JComboBox combType;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel6;
 private javax.swing.JTextField tfdName;
 private javax.swing.JPasswordField tfdPwd;
 private javax.swing.JPasswordField tfdPwd2;
 private javax.swing.JTextField tfdUuid;
 // End of variables declaration//GEN-END:variables

}

ListPanel類:

cn.hncu.bookStore.user.ui;
ListPanel類:

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

package cn.hncu.bookStore.user.ui;

import java.util.List;

import javax.swing.JFrame;

import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;

/**
 * 表現(xiàn)層-用戶列表面板
 * 
 * @author 陳浩翔
 * @version 1.0
 */
public class ListPanel extends javax.swing.JPanel {
 private JFrame mainFrame = null;

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

 /**
  * 讀取所有用戶并添加進列表
  */
 private void myInitData() {
  UserEbi user = UserEbiFactory.getUserEbi();
  List<UserModel> list = user.getAll();
  userLists.setListData(list.toArray());
 }

 /** 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() {

  jScrollPane1 = new javax.swing.JScrollPane();
  userLists = new javax.swing.JList();
  jLabel1 = new javax.swing.JLabel();
  btnToAdd = new javax.swing.JButton();

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

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

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

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

  add(jScrollPane1);
  jScrollPane1.setBounds(150, 150, 480, 230);

  jLabel1.setFont(new java.awt.Font("Tahoma", 1, 48));
  jLabel1.setForeground(new java.awt.Color(204, 0, 51));
  jLabel1.setText("User List");
  add(jLabel1);
  jLabel1.setBounds(270, 30, 260, 80);

  btnToAdd.setFont(new java.awt.Font("Dialog", 1, 18));
  btnToAdd.setText("\u6dfb\u52a0\u7528\u6237");
  btnToAdd.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnToAddActionPerformed(evt);
   }
  });
  add(btnToAdd);
  btnToAdd.setBounds(60, 420, 150, 50);
 }// </editor-fold>
 //GEN-END:initComponents

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

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

}

UserModel類:

cn.hncu.bookStore.user.vo;
UserModel類:
用戶值對象模塊:

package cn.hncu.bookStore.user.vo;

import java.io.Serializable;

import cn.hncu.bookStore.common.UserTypeEnum;

/**
 * @author 陳浩翔
 * @version 1.0
 * 
 * <br/>
 * 用于保存用戶信息的值對象<br/>
 * 1、可序列化<br/>
 * 2、私有化所有變量成員,補setter-getters方法<br/>
 * 3、寫equals和hashCode方法----用主鍵(uuid)唯一標(biāo)識碼<br/>
 * 4、toString方法<br/>
 * 5,空參構(gòu)造方法<br/>
 */

public class UserModel implements Serializable{
 private String uuid;//用戶唯一標(biāo)識碼
 private String name;//用戶名
 private int type;//用戶類型
 private String pwd;//用戶密碼
 public UserModel() {
 }

 /**
  * 功能:得到uuid-用戶唯一的標(biāo)識碼
  * 
  * @return 返回uuid-用戶唯一的標(biāo)識碼
  */
 public String getUuid() {
  return uuid;
 }

 /**
  * 功能:設(shè)置uuid-用戶唯一的標(biāo)識碼
  * @param uuid-用戶唯一的標(biāo)識碼-String型參數(shù)
  */
 public void setUuid(String uuid) {
  this.uuid = uuid;
 }

 /**
  * 功能:得到用戶的用戶名
  * @return---name-用戶名
  */
 public String getName() {
  return name;
 }

 /**
  * 功能:設(shè)置用戶的用戶名
  * 
  * @param name--用戶設(shè)置的用戶名,String型參數(shù)
  */
 public void setName(String name) {
  this.name = name;
 }

 /**
  * 功能:得到用戶的類型:
  * 1——表示為admin,可以進行全部操作
  * 2——表示為能操作圖書模塊的人員
  * 3——表示為能操作進貨模塊的人員
  * 4——表示為能操作銷售模塊的人員
  * 5——表示為能操作庫存模塊的人員
  * @return 用戶的類型
  */
 public int getType() {
  return type;
 }

 /**
  * 功能:設(shè)置用戶的類型:
  * 1——表示為admin,可以進行全部操作
  * 2——表示為能操作圖書模塊的人員
  * 3——表示為能操作進貨模塊的人員
  * 4——表示為能操作銷售模塊的人員
  * 5——表示為能操作庫存模塊的人員
  * @param type--用戶的類型-int型參數(shù)
  */
 public void setType(int type) {
  this.type = type;
 }

 /**
  *功能:得到用戶的密碼
  * @return String型,用戶的密碼
  */
 public String getPwd() {
  return pwd;
 }

 /**
  * 功能:設(shè)置用戶的密碼
  * @param pwd--String型參數(shù)
  */
 public void setPwd(String pwd) {
  this.pwd = pwd;
 }


 @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;
  UserModel other = (UserModel) 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 + "," + UserTypeEnum.getNameByType(type);
 }

}


 UserQueryModel類:

cn.hncu.bookStore.user.vo;
UserQueryModel類:
雖然沒有代碼,但不能不寫!這是查找用戶時需要的。
原因我在系列一寫了。

package cn.hncu.bookStore.user.vo;
/**
 * 
 * @author 陳浩翔
 *
 * @version 1.0
 */
public class UserQueryModel extends UserModel{

}


 FileIoUtil類:

cn.hncu.bookStore.util;
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;

/**
 * 用戶的公用數(shù)據(jù)讀取寫入類
 * @author 陳浩翔
 *
 * @version 1.0
 */
public class FileIoUtil {

 public FileIoUtil() {
 }


 /**
  * 從數(shù)據(jù)庫中讀取所有的數(shù)據(jù)并返回出來
  * 
  * @param fileName:(數(shù)據(jù)表對應(yīng)的文件名字)
  * @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, "數(shù)據(jù)表不存在!");
   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("數(shù)據(jù)庫關(guān)閉失敗");
    }
   }
  }
  return list;
 }


 /**
  * 寫入一個list集合進入數(shù)據(jù)文件fileName
  * 
  * @param list(需要存儲的數(shù)據(jù)集合)
  * @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("數(shù)據(jù)庫關(guān)閉失敗!");
    }
   }
  }
 }

}


BookStore類:(含main方法)
cn.hncu.bookStore;
BookStore類:
用戶模塊的main方法在這個類中:

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

package cn.hncu.bookStore;

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

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

 /** Creates new form BookStore */
 public BookStore() {
  initComponents();
  this.setContentPane(new ListPanel(this));
  this.setResizable(false);//不能縮放
  this.setDefaultCloseOperation(EXIT_ON_CLOSE);
 }

 /** 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() {

  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();

  setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  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);

  setJMenuBar(menuBar);

  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
    getContentPane());
  getContentPane().setLayout(layout);
  layout.setHorizontalGroup(layout.createParallelGroup(
    javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
    Short.MAX_VALUE));
  layout.setVerticalGroup(layout.createParallelGroup(
    javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 279,
    Short.MAX_VALUE));

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

 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.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

}

今天就寫到這里的,未完待續(xù)。。。
目前的添加有一個小bug,就是添加用戶時,什么都不輸入,
只選擇用戶類型,也能創(chuàng)建!下次我會修復(fù)的。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring Bean常用依賴注入方式詳解

    Spring Bean常用依賴注入方式詳解

    這篇文章主要介紹了Spring Bean常用三種依賴注入方式詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-07-07
  • Spring配置文件使用占位符配置方式

    Spring配置文件使用占位符配置方式

    這篇文章主要介紹了Spring配置文件使用占位符配置方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • 利用Java理解sql的語法(實例講解)

    利用Java理解sql的語法(實例講解)

    下面小編就為大家分享一篇利用Java理解sql的語法(實例講解),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-11-11
  • springboot數(shù)據(jù)訪問和數(shù)據(jù)視圖的使用方式詳解

    springboot數(shù)據(jù)訪問和數(shù)據(jù)視圖的使用方式詳解

    這篇文章主要為大家介紹了springboot數(shù)據(jù)訪問和數(shù)據(jù)視圖的使用方式詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • mybatis and,or復(fù)合查詢操作

    mybatis and,or復(fù)合查詢操作

    這篇文章主要介紹了mybatis and,or復(fù)合查詢操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Java集合之CopyOnWriteArrayList詳解

    Java集合之CopyOnWriteArrayList詳解

    這篇文章主要介紹了Java集合之CopyOnWriteArrayList詳解,CopyOnWriteArrayList是ArrayList的線程安全版本,內(nèi)部也是通過數(shù)組實現(xiàn),每次對數(shù)組的修改都完全拷貝一份新的數(shù)組來修改,修改完了再替換掉老數(shù)組,這樣保證了只阻塞寫操作,需要的朋友可以參考下
    2023-12-12
  • Java 位運算符>>與>>>區(qū)別案例詳解

    Java 位運算符>>與>>>區(qū)別案例詳解

    這篇文章主要介紹了Java 位運算符>>與>>>區(qū)別案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • 指定jdk啟動jar包的方法總結(jié)

    指定jdk啟動jar包的方法總結(jié)

    這篇文章主要給大家總結(jié)介紹了關(guān)于指定jdk啟動jar包的方法,文中通過實例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2023-07-07
  • java8 List<Object>去掉重復(fù)對象的幾種方法

    java8 List<Object>去掉重復(fù)對象的幾種方法

    本文主要介紹了java8 List<Object>去掉重復(fù)對象的幾種方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • java線程的run()沒有返回值怎么辦?

    java線程的run()沒有返回值怎么辦?

    java線程的run()沒有返回值怎么辦?本文給出了java線程的run()返回值為空的解決辦法,感興趣的小伙伴們可以參考一下
    2016-01-01

最新評論