一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語言 - JAVA教程 - Java設(shè)計(jì)模塊系列之書店管理系統(tǒng)單機(jī)版(二)

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

2020-06-06 14:53qq_26525215 JAVA教程

這篇文章主要為大家詳細(xì)介紹了Java單機(jī)版的書店管理系統(tǒng)設(shè)計(jì)模塊和思想第二章,感興趣的小伙伴們可以參考一下

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

介紹

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

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

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

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

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

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

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

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

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

UserTypeEnum類:

cn.hncu.bookStore.common;
UserTypeEnum類:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cn.hncu.bookStore.common;
 
/**
 * 功能:用戶類型的枚舉!<br/>
 * 定義在公共模塊。<br/>
 * 變量:<br/>
 * ADMIN(1,"超級(jí)管理員"),<br/>
 * BOOK(2,"圖書管理員"),<br/>
 * IN(3,"進(jìn)貨管理員"),<br/>
 * OUT(4,"銷售管理員"),<br/>
 * STOCK(5,"庫存管理員");<br/>
 * @author chx
 * @version 1.0
 */
public enum UserTypeEnum {
 ADMIN(1,"超級(jí)管理員"),
 BOOK(2,"圖書管理員"),
 IN(3,"進(jìn)貨管理員"),
 OUT(4,"銷售管理員"),
 STOCK(5,"庫存管理員");
 
 private final int type;
 private final String name;
 
 /**
  * 初始化枚舉變量名字
  * @param type---枚舉變量對(duì)應(yīng)的整型數(shù)字
  * @param name---枚舉變量對(duì)應(yīng)的String型名字
  */
 private UserTypeEnum(int type, String name) {
  this.type=type;
  this.name=name;
 }
 
 /**
  * 得到當(dāng)前枚舉變量的數(shù)字
  * @return---type-編號(hào)
  */
 public int getType() {
  return type;
 }
 
 /**
  * 得到當(dāng)前枚舉變量的中文名字
  * @return---name-中文名字
  */
 public String getName() {
  return name;
 }
 
 /**
  * 根據(jù)枚舉變量的int數(shù)字得到數(shù)字對(duì)應(yīng)的枚舉變量的中文名字
  * @param type---需要傳入的int型參數(shù)
  * @return ---如果存在這樣的數(shù)字對(duì)應(yīng)的枚舉變量,就返回這個(gè)枚舉變量的中文名字。
  * <br/>---如果不存在這樣的數(shù)字對(duì)應(yīng)的枚舉變量,就拋出一個(gè)異常信息。
  */
 public static String getNameByType(int type){
  for(UserTypeEnum userType:UserTypeEnum.values()){
   if(userType.getType()==type){
    return userType.getName();
   }
  }
  throw new IllegalArgumentException("枚舉中沒有對(duì)應(yīng)的用戶類型:"+type);
 }
 
 /**
  * 根據(jù)枚舉變量的name中文名字得到name對(duì)應(yīng)的枚舉變量的int型type
  * @param name---需要傳入的String型名字
  * @return ---如果存在這樣的名字對(duì)應(yīng)的枚舉變量,就返回這個(gè)枚舉變量對(duì)應(yīng)的type-int
  * <br/> ---如果不存在這樣的名字對(duì)應(yīng)的枚舉變量,就拋出一個(gè)異常信息
  */
 public static int getTypeByName(String name){
  for(UserTypeEnum userType:UserTypeEnum.values()){
   if(userType.getName().equals(name)){
    return userType.getType();
   }
  }
  throw new IllegalArgumentException("枚舉中沒有對(duì)應(yīng)的用戶類型:"+name);
 }
}

 UserEbi接口:

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)建一個(gè)用戶
  *
  * @param userModel---將要?jiǎng)?chuàng)建的用戶數(shù)據(jù)
  * @return---true表示創(chuàng)建成功,false表示創(chuàng)建失敗
  */
 public boolean create(UserModel user);
 
 /**
  * 功能:根據(jù)用戶的唯一標(biāo)識(shí)碼uuid刪除一個(gè)用戶
  *
  * @param uuid---用戶唯一的標(biāo)識(shí)碼,每個(gè)用戶都不會(huì)相同
  * @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---一個(gè)UserModel集合,也就是用戶的數(shù)據(jù)
  */
 public List<UserModel> getAll();
 
 /**
  * 功能:按照一定的查找條件進(jìn)行查找,
  * <br/>
  * 把滿足查找條件的用戶數(shù)據(jù)返回。
  *
  * @param uqm---被封裝的查找條件
  * @return---滿足查找條件的用戶數(shù)據(jù)集合
  */
 public List<UserModel> getbyCondition(UserQueryModel uqm);
 
 /**
  * 功能:得到一個(gè)確定的用戶的數(shù)據(jù)資料
  *
  * @param uuid---用戶唯一標(biāo)識(shí)碼
  * @return ---返回按這個(gè)唯一標(biāo)識(shí)碼找到的用戶數(shù)據(jù)
  */
 public UserModel getSingle(String uuid);
}

 UserEbo類:

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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類:

?
1
2
3
4
5
6
7
8
9
10
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接口:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)建一個(gè)用戶
  *
  * @param userModel---將要?jiǎng)?chuàng)建的用戶數(shù)據(jù)
  * @return---true表示創(chuàng)建成功,false表示創(chuàng)建失敗
  */
 public boolean create(UserModel user);
 
 /**
  * 功能:根據(jù)用戶的唯一標(biāo)識(shí)碼uuid刪除一個(gè)用戶
  *
  * @param uuid---用戶唯一的標(biāo)識(shí)碼,每個(gè)用戶都不會(huì)相同
  * @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---一個(gè)UserModel集合,也就是用戶的數(shù)據(jù)
  */
 public List<UserModel> getAll();
 
 /**
  * 功能:按照一定的查找條件進(jìn)行查找,
  * <br/>
  * 把滿足查找條件的用戶數(shù)據(jù)返回。
  *
  * @param uqm---被封裝的查找條件
  * @return---滿足查找條件的用戶數(shù)據(jù)集合
  */
 public List<UserModel> getbyCondition(UserQueryModel uqm);
 
 /**
  * 功能:得到一個(gè)確定的用戶的數(shù)據(jù)資料
  *
  * @param uuid---用戶唯一標(biāo)識(shí)碼
  * @return ---返回按這個(gè)唯一標(biāo)識(shí)碼找到的用戶數(shù)據(jù)
  */
 public UserModel getSingle(String uuid);
 
}

 UserDaoFactory類:

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 一個(gè)dao的實(shí)例
 * @author 陳浩翔
 *
 * @version 1.0
 *
 */
public class UserDaoFactory {
 public static UserDao getUserDao(){
  return new UserDaoSerImpl();
 }
}

 UserDaoSerImpl類:

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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/>
 * 對(duì)用戶數(shù)據(jù)處理的具體實(shí)現(xiàn)類 ----實(shí)現(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)存在,再?zèng)Q定是否創(chuàng)建
  for (UserModel userModel : list) {
   // 如果2個(gè)用戶的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)存在,再?zèng)Q定是否刪除
 
  // 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個(gè)用戶的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)存在,再?zèng)Q定是否創(chuàng)建
  for (int i = 0; i < list.size(); i++) {
   // uuid是不能改的,通過uuid來找到那個(gè)用戶數(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)存在,存在就返回那個(gè)用戶
  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類:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * 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[] { "請(qǐng)選擇..." }));
  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 返回按鈕的點(diǎn)擊監(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, "兩次密碼輸入不一致,請(qǐng)重新輸入!");
   return;
  }
  int type = 0;
 
  try {
   type = UserTypeEnum.getTypeByName(combType.getSelectedItem()
     .toString());
  } catch (Exception e) {
   JOptionPane.showMessageDialog(null, "請(qǐng)指定用戶類型!");
   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類:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * 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();
 }
 
 /**
  * 讀取所有用戶并添加進(jìn)列表
  */
 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類:
用戶值對(duì)象模塊:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package cn.hncu.bookStore.user.vo;
 
import java.io.Serializable;
 
import cn.hncu.bookStore.common.UserTypeEnum;
 
/**
 * @author 陳浩翔
 * @version 1.0
 *
 * <br/>
 * 用于保存用戶信息的值對(duì)象<br/>
 * 1、可序列化<br/>
 * 2、私有化所有變量成員,補(bǔ)setter-getters方法<br/>
 * 3、寫equals和hashCode方法----用主鍵(uuid)唯一標(biāo)識(shí)碼<br/>
 * 4、toString方法<br/>
 * 5,空參構(gòu)造方法<br/>
 */
 
public class UserModel implements Serializable{
 private String uuid;//用戶唯一標(biāo)識(shí)碼
 private String name;//用戶名
 private int type;//用戶類型
 private String pwd;//用戶密碼
 public UserModel() {
 }
 
 /**
  * 功能:得到uuid-用戶唯一的標(biāo)識(shí)碼
  *
  * @return 返回uuid-用戶唯一的標(biāo)識(shí)碼
  */
 public String getUuid() {
  return uuid;
 }
 
 /**
  * 功能:設(shè)置uuid-用戶唯一的標(biāo)識(shí)碼
  * @param uuid-用戶唯一的標(biāo)識(shí)碼-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,可以進(jìn)行全部操作
  * 2——表示為能操作圖書模塊的人員
  * 3——表示為能操作進(jìn)貨模塊的人員
  * 4——表示為能操作銷售模塊的人員
  * 5——表示為能操作庫存模塊的人員
  * @return 用戶的類型
  */
 public int getType() {
  return type;
 }
 
 /**
  * 功能:設(shè)置用戶的類型:
  * 1——表示為admin,可以進(jìn)行全部操作
  * 2——表示為能操作圖書模塊的人員
  * 3——表示為能操作進(jìn)貨模塊的人員
  * 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類:
雖然沒有代碼,但不能不寫!這是查找用戶時(shí)需要的。
原因我在系列一寫了。

?
1
2
3
4
5
6
7
8
9
10
package cn.hncu.bookStore.user.vo;
/**
 *
 * @author 陳浩翔
 *
 * @version 1.0
 */
public class UserQueryModel extends UserModel{
 
}

 FileIoUtil類:

cn.hncu.bookStore.util;
FileIoUtil類:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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ù)表對(duì)應(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;
 }
 
 
 /**
  * 寫入一個(gè)list集合進(jìn)入數(shù)據(jù)文件fileName
  *
  * @param list(需要存儲(chǔ)的數(shù)據(jù)集合)
  * @param fileName(寫入到哪個(gè)文件的文件名字)
  */
 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方法在這個(gè)類中:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * 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ù)。。。
目前的添加有一個(gè)小bug,就是添加用戶時(shí),什么都不輸入,
只選擇用戶類型,也能創(chuàng)建!下次我會(huì)修復(fù)的。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://blog.csdn.net/qq_26525215/article/details/51089734

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91香蕉国产在线观看免费永久 | 色综合视频在线 | 欧美涩区 | 91九色最新地址 | 黄网在线观看免费网站台湾swag | www.精品在线 | 国产精品密播放国产免费看 | 日韩成人一区ftp在线播放 | 美女流白浆 | 青青精品视频 | 日日射视频 | 91手机看片国产永久免费 | 99热这里只有精 | 免费日批软件 | 精品福利视频一区二区三区 | 日韩日b视频| 91尤物在线播放 | 欧美男男gaygaysxxx | 国产欧美一区二区成人影院 | 狠狠干综合网 | 欧美日韩国产在线人成dvd | 成人久久18免费网站入口 | 超h高h肉h文武侠 | 色综合天天五月色 | h动态图男女啪啪27报 | 欧美日韩精彩视频 | 国产精品反差婊在线观看 | 亚洲国产一区 | 手机看片自拍自自拍日韩免费 | 成在线人免费 | 我把校花黑色蕾丝胸罩脱了 | 精品亚洲欧美中文字幕在线看 | 日韩欧美一级大片 | 韩日视频在线 | 久久久无码精品无码国产人妻丝瓜 | 国产成人福利免费观看 | 外国a级片| 男女18一级大黄毛片免 | bestialitysex杂交 bedfriend泰剧全集免费观看 | 欧美三级不卡在线观线看高清 | 男同精品视频免费观看网站 |