国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Java設計模塊系列之書店管理系統單機版(二)

2019-11-26 13:56:48
字體:
來源:轉載
供稿:網友

Java-單機版的書店管理系統(練習設計模塊和思想_系列 一 ): //m.survivalescaperooms.com/article/91004.htm

介紹

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

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

現在的代碼分層:

現在的程序運行后的圖片:

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

 

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---枚舉變量對應的整型數字  * @param name---枚舉變量對應的String型名字  */ private UserTypeEnum(int type, String name) {  this.type=type;  this.name=name; } /**  * 得到當前枚舉變量的數字  * @return---type-編號  */ public int getType() {  return type; } /**  * 得到當前枚舉變量的中文名字  * @return---name-中文名字  */ public String getName() {  return name; } /**  * 根據枚舉變量的int數字得到數字對應的枚舉變量的中文名字  * @param type---需要傳入的int型參數  * @return ---如果存在這樣的數字對應的枚舉變量,就返回這個枚舉變量的中文名字。  * <br/>---如果不存在這樣的數字對應的枚舉變量,就拋出一個異常信息。  */ public static String getNameByType(int type){  for(UserTypeEnum userType:UserTypeEnum.values()){   if(userType.getType()==type){    return userType.getName();   }  }  throw new IllegalArgumentException("枚舉中沒有對應的用戶類型:"+type); } /**  * 根據枚舉變量的name中文名字得到name對應的枚舉變量的int型type  * @param name---需要傳入的String型名字  * @return ---如果存在這樣的名字對應的枚舉變量,就返回這個枚舉變量對應的type-int  * <br/> ---如果不存在這樣的名字對應的枚舉變量,就拋出一個異常信息  */  public static int getTypeByName(String name){  for(UserTypeEnum userType:UserTypeEnum.values()){   if(userType.getName().equals(name)){    return userType.getType();   }  }  throw new IllegalArgumentException("枚舉中沒有對應的用戶類型:"+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 { /**  * 功能:創建一個用戶  *   * @param userModel---將要創建的用戶數據  * @return---true表示創建成功,false表示創建失敗  */ public boolean create(UserModel user); /**  * 功能:根據用戶的唯一標識碼uuid刪除一個用戶  *   * @param uuid---用戶唯一的標識碼,每個用戶都不會相同  * @return---true表示刪除成功,false表示刪除失敗  */ public boolean delete(String uuid); /**  * 功能:修改用戶的數據資料  *   * @param user---需要修改的用戶數據參數名  * @return 返回true-表示修改成功了,返回false-表示修改失敗  */ public boolean update(UserModel user); /**  * 功能:得到所有的用戶數據  *   * @return---一個UserModel集合,也就是用戶的數據  */ public List<UserModel> getAll(); /**  * 功能:按照一定的查找條件進行查找,  * <br/>  * 把滿足查找條件的用戶數據返回。  *   * @param uqm---被封裝的查找條件  * @return---滿足查找條件的用戶數據集合  */ public List<UserModel> getbyCondition(UserQueryModel uqm); /**  * 功能:得到一個確定的用戶的數據資料  *   * @param uuid---用戶唯一標識碼  * @return ---返回按這個唯一標識碼找到的用戶數據  */ 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 * 用戶模塊的數據層接口 */public interface UserDao { /**  * 功能:創建一個用戶  *   * @param userModel---將要創建的用戶數據  * @return---true表示創建成功,false表示創建失敗  */ public boolean create(UserModel user); /**  * 功能:根據用戶的唯一標識碼uuid刪除一個用戶  *   * @param uuid---用戶唯一的標識碼,每個用戶都不會相同  * @return---true表示刪除成功,false表示刪除失敗  */ public boolean delete(String uuid); /**  * 功能:修改用戶的數據資料  *   * @param user---需要修改的用戶數據參數名  * @return 返回true-表示修改成功了,返回false-表示修改失敗  */ public boolean update(UserModel user); /**  * 功能:得到所有的用戶數據  *   * @return---一個UserModel集合,也就是用戶的數據  */ public List<UserModel> getAll(); /**  * 功能:按照一定的查找條件進行查找,  * <br/>  * 把滿足查找條件的用戶數據返回。  *   * @param uqm---被封裝的查找條件  * @return---滿足查找條件的用戶數據集合  */ public List<UserModel> getbyCondition(UserQueryModel uqm); /**  * 功能:得到一個確定的用戶的數據資料  *   * @param uuid---用戶唯一標識碼  * @return ---返回按這個唯一標識碼找到的用戶數據  */ 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/> * 對用戶數據處理的具體實現類 ----實現了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先把已有的數據反序列化(讀)出來  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);  // 2判斷該用戶是否已經存在,再決定是否創建  for (UserModel userModel : list) {   // 如果2個用戶的uuid相等,用戶就是相同的   if (userModel.getUuid().equals(user.getUuid())) {    return false;// 用戶已經存在了,返回false   }  }  // 3如果用戶不存在,就創建  list.add(user);  FileIoUtil.write2file(list, FILE_NAME);  return true;// 創建成功,返回true } @Override public boolean delete(String uuid) {  // 1先把已有的數據反序列化(讀)出來  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);  // 2判斷該用戶是否已經存在,再決定是否刪除  // 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先把已有的數據反序列化(讀)出來  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);  // 2判斷該用戶是否已經存在,再決定是否創建  for (int i = 0; i < list.size(); i++) {   // uuid是不能改的,通過uuid來找到那個用戶數據,再修改就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先把已有的數據反序列化(讀)出來  List<UserModel> list = FileIoUtil.readFormFile(FILE_NAME);  // 2判斷該用戶是否已經存在,存在就返回那個用戶  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(); } /**  *監聽返回按鈕  * @param 返回按鈕的點擊監聽  */ private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {  back(); } private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {  //1收集參數  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組織參數  UserModel user = new UserModel();  user.setName(name);  user.setPwd(pwd);  user.setType(type);  user.setUuid(uuid);  //3調用邏輯層  UserEbi ebi = UserEbiFactory.getUserEbi();  //4根據調用返回結果導向不同頁面  if (ebi.create(user)) {   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.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;/** * 表現層-用戶列表面板 *  * @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)唯一標識碼<br/> * 4、toString方法<br/> * 5,空參構造方法<br/> */public class UserModel implements Serializable{ private String uuid;//用戶唯一標識碼 private String name;//用戶名 private int type;//用戶類型 private String pwd;//用戶密碼 public UserModel() { } /**  * 功能:得到uuid-用戶唯一的標識碼  *   * @return 返回uuid-用戶唯一的標識碼  */ public String getUuid() {  return uuid; } /**  * 功能:設置uuid-用戶唯一的標識碼  * @param uuid-用戶唯一的標識碼-String型參數  */ public void setUuid(String uuid) {  this.uuid = uuid; } /**  * 功能:得到用戶的用戶名  * @return---name-用戶名  */ public String getName() {  return name; } /**  * 功能:設置用戶的用戶名  *   * @param name--用戶設置的用戶名,String型參數  */ public void setName(String name) {  this.name = name; } /**  * 功能:得到用戶的類型:  * 1――表示為admin,可以進行全部操作  * 2――表示為能操作圖書模塊的人員  * 3――表示為能操作進貨模塊的人員  * 4――表示為能操作銷售模塊的人員  * 5――表示為能操作庫存模塊的人員  * @return 用戶的類型  */ public int getType() {  return type; } /**  * 功能:設置用戶的類型:  * 1――表示為admin,可以進行全部操作  * 2――表示為能操作圖書模塊的人員  * 3――表示為能操作進貨模塊的人員  * 4――表示為能操作銷售模塊的人員  * 5――表示為能操作庫存模塊的人員  * @param type--用戶的類型-int型參數  */ public void setType(int type) {  this.type = type; } /**  *功能:得到用戶的密碼  * @return String型,用戶的密碼  */ public String getPwd() {  return pwd; } /**  * 功能:設置用戶的密碼  * @param pwd--String型參數  */ 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;/** * 用戶的公用數據讀取寫入類 * @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("數據庫關閉失敗!");    }   }  } }}

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}

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙口市| 厦门市| 德化县| 通河县| 五指山市| 霍林郭勒市| 中西区| 永寿县| 麻栗坡县| 新竹县| 屏东市| 金川县| 康定县| 稷山县| 岐山县| 沈阳市| 潼南县| 桦甸市| 那坡县| 莫力| 娄烦县| 自贡市| 红桥区| 隆子县| 封丘县| 宁夏| 沁水县| 柳河县| 通辽市| 光泽县| 修武县| 保德县| 延庆县| 台北县| 万源市| 孝昌县| 呼和浩特市| 安平县| 镇远县| 桦南县| 清苑县|