服务器之家

服务器之家 > 正文

Java设计模块系列之书店管理系统单机版(三)

时间:2020-06-07 12:18     来源/作者:qq_26525215

介绍

今天对系列二的一个添加用户的输入小bug进行了解决, 增加了用户模块的,删除用户,和修改用户模块。

下面的代码是相对于系列二来说进行了修改或者是增加的类.

先看AddPanel类的修改:
在收集参数的时候进行防范就可防止那个bug了。

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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * 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(330, 30, 230, 80);
 
  jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel2.setText("\u7528\u6237\u7c7b\u578b:");
  add(jLabel2);
  jLabel2.setBounds(90, 310, 90, 30);
 
  tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
  tfdName.setAutoscrolls(false);
  add(tfdName);
  tfdName.setBounds(470, 160, 120, 30);
 
  jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel3.setText("uuid:");
  add(jLabel3);
  jLabel3.setBounds(120, 160, 50, 30);
 
  tfdUuid.setFont(new java.awt.Font("Dialog", 1, 12));
  add(tfdUuid);
  tfdUuid.setBounds(190, 160, 110, 30);
 
  jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel4.setText("\u59d3\u540d:");
  add(jLabel4);
  jLabel4.setBounds(410, 160, 50, 30);
 
  tfdPwd2.setFont(new java.awt.Font("宋体", 1, 18));
  add(tfdPwd2);
  tfdPwd2.setBounds(470, 240, 170, 30);
 
  jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel5.setText("\u5bc6\u7801:");
  add(jLabel5);
  jLabel5.setBounds(120, 240, 50, 30);
 
  jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel6.setText("\u786e\u8ba4\u5bc6\u7801:");
  add(jLabel6);
  jLabel6.setBounds(380, 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(190, 310, 160, 30);
 
  tfdPwd.setFont(new java.awt.Font("宋体", 1, 18));
  add(tfdPwd);
  tfdPwd.setBounds(190, 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(190, 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(520, 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());
  //System.out.println(uuid);
 
  //System.out.println(uuid+","+name+","+pwd);
  if (uuid.equals("") || uuid.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户ID为空,请重新输入!");
   return;
  }
 
  if (name.equals("") || name.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户名为空,请重新输入!");
   return;
  }
 
  if (!pwd.equals(pwd2) || pwd.equals("") || pwd.equals(null)
    || pwd2.equals("") || pwd2.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "两次密码输入不一致或密码为空,请重新输入!");
   return;
  }
  int type = 0;
 
  try {
   type = UserTypeEnum.getTypeByName(combType.getSelectedItem()
     .toString());
  } catch (Exception e) {
   JOptionPane.showMessageDialog(mainFrame, "请指定用户类型!");
   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
 
}

cn.hncu.bookStore.user.ui;

DeletePanel类:(删除用户模块)

?
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
/*
 * DeletePanel.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 陈浩翔
 *
 * @version 1.0
 */
public class DeletePanel extends javax.swing.JPanel {
 private JFrame mainFrame = null;
 private String uuid = null;
 
 /** Creates new form DeletePanel
  * @param uuid */
 public DeletePanel(JFrame mainFrame, String uuid) {
  this.mainFrame = mainFrame;
  this.uuid = uuid;
  initComponents();
  myInitData();
 }
 
 private void myInitData() {
  UserEbi user = UserEbiFactory.getUserEbi();
  UserModel userModel = user.getSingle(uuid);
  tfdName.setText(userModel.getName());
  tfdUuid.setText(userModel.getUuid());
  tfdPwd.setText(userModel.getPwd());
  tfdType.setText(UserTypeEnum.getNameByType(userModel.getType()));
 
  tfdName.setEditable(false);
  tfdPwd.setEditable(false);
  tfdType.setEditable(false);
  tfdUuid.setEditable(false);
 
 }
 
 //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();
  jLabel5 = new javax.swing.JLabel();
  tfdPwd = new javax.swing.JTextField();
  tfdType = new javax.swing.JTextField();
  btnBack = new javax.swing.JButton();
  btnDelete = 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("\u5220\u9664\u7528\u6237");
  add(jLabel1);
  jLabel1.setBounds(330, 30, 230, 80);
 
  jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel2.setText("\u7528\u6237\u7c7b\u578b:");
  add(jLabel2);
  jLabel2.setBounds(100, 310, 90, 30);
 
  tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
  tfdName.setAutoscrolls(false);
  add(tfdName);
  tfdName.setBounds(480, 160, 120, 30);
 
  jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel3.setText("uuid:");
  add(jLabel3);
  jLabel3.setBounds(130, 160, 50, 30);
 
  tfdUuid.setFont(new java.awt.Font("Dialog", 0, 11));
  add(tfdUuid);
  tfdUuid.setBounds(200, 160, 110, 30);
 
  jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel4.setText("\u59d3\u540d:");
  add(jLabel4);
  jLabel4.setBounds(420, 160, 50, 30);
 
  jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel5.setText("\u5bc6\u7801:");
  add(jLabel5);
  jLabel5.setBounds(130, 240, 50, 30);
 
  tfdPwd.setFont(new java.awt.Font("Tahoma", 1, 12));
  add(tfdPwd);
  tfdPwd.setBounds(200, 240, 160, 30);
 
  tfdType.setFont(new java.awt.Font("Dialog", 1, 12));
  add(tfdType);
  tfdType.setBounds(200, 310, 160, 30);
 
  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(540, 450, 120, 60);
 
  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(210, 450, 120, 60);
 }// </editor-fold>
 //GEN-END:initComponents
 
 private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
  //3调用逻辑层
  if (UserEbiFactory.getUserEbi().delete(uuid)) {
   back();
  } else {
   JOptionPane.showMessageDialog(mainFrame, "该用户已经不存在!");
  }
 
  //4根据调用返回结果导向不同页面
 
 }
 
 private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
  back();
 }
 
 private void back() {
  mainFrame.setContentPane(new ListPanel(mainFrame));
  mainFrame.validate();
 }
 
 //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 jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JTextField tfdName;
 private javax.swing.JTextField tfdPwd;
 private javax.swing.JTextField tfdType;
 private javax.swing.JTextField tfdUuid;
 // End of variables declaration//GEN-END:variables
 
}

cn.hncu.bookStore.user.ui;

UpdatePanel类:(修改用户模块)

?
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * UpdatePanel.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;
 
/**
 *
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class UpdatePanel extends javax.swing.JPanel {
 private JFrame mainFrame = null;
 private String uuid = null;
 
 /**
  * Creates new form UpdatePanel
  *
  * @param uuid
  * @param mainFrame
  */
 public UpdatePanel(JFrame mainFrame, String uuid) {
  this.mainFrame = mainFrame;
  this.uuid = uuid;
  initComponents();
  myInitData();
 }
 
 private void myInitData() {
  UserEbi ebi = UserEbiFactory.getUserEbi();
  UserModel user = ebi.getSingle(uuid);
  tfdUuid.setText(user.getUuid());
  tfdUuid.setEditable(false);
 
  tfdName.setText(user.getName());
  tfdPwd.setText(user.getPwd());
  tfdPwd2.setText(user.getPwd());
 
  combType.removeAllItems();
  String usert = UserTypeEnum.getNameByType(user.getType());
  combType.addItem(usert);
  for (UserTypeEnum userType : UserTypeEnum.values()) {
   if (!userType.getName().equals(usert)) {
    combType.addItem(userType.getName());
   }
  }
 
 }
 
 // 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();
  tfdPwd = new javax.swing.JPasswordField();
  combType = new javax.swing.JComboBox();
  btnBack = new javax.swing.JButton();
  btnUpdate = 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("\u4fee\u6539\u7528\u6237");
  add(jLabel1);
  jLabel1.setBounds(320, 30, 230, 80);
 
  jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel2.setText("\u7528\u6237\u7c7b\u578b:");
  add(jLabel2);
  jLabel2.setBounds(90, 310, 90, 30);
 
  tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
  tfdName.setAutoscrolls(false);
  add(tfdName);
  tfdName.setBounds(470, 160, 120, 30);
 
  jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel3.setText("uuid:");
  add(jLabel3);
  jLabel3.setBounds(120, 160, 50, 30);
 
  tfdUuid.setFont(new java.awt.Font("Dialog", 1, 12));
  add(tfdUuid);
  tfdUuid.setBounds(190, 160, 110, 30);
 
  jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel4.setText("\u59d3\u540d:");
  add(jLabel4);
  jLabel4.setBounds(410, 160, 50, 30);
 
  tfdPwd2.setFont(new java.awt.Font("Dialog", 1, 18));
  add(tfdPwd2);
  tfdPwd2.setBounds(470, 240, 170, 30);
 
  jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel5.setText("\u5bc6\u7801:");
  add(jLabel5);
  jLabel5.setBounds(120, 240, 50, 30);
 
  jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel6.setText("\u786e\u8ba4\u5bc6\u7801:");
  add(jLabel6);
  jLabel6.setBounds(380, 240, 90, 30);
 
  tfdPwd.setFont(new java.awt.Font("宋体", 1, 18));
  add(tfdPwd);
  tfdPwd.setBounds(190, 240, 160, 30);
 
  combType.setFont(new java.awt.Font("Dialog", 1, 12));
  combType.setForeground(new java.awt.Color(51, 0, 255));
  combType.setModel(new javax.swing.DefaultComboBoxModel(
    new String[] { "" }));
  add(combType);
  combType.setBounds(190, 310, 170, 30);
 
  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(500, 430, 120, 60);
 
  btnUpdate.setFont(new java.awt.Font("Dialog", 1, 24));
  btnUpdate.setForeground(new java.awt.Color(0, 204, 204));
  btnUpdate.setText("\u4fee\u6539");
  btnUpdate.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnUpdateActionPerformed(evt);
   }
  });
  add(btnUpdate);
  btnUpdate.setBounds(170, 430, 120, 60);
 }// </editor-fold>
  // GEN-END:initComponents
 
 private void btnUpdateActionPerformed(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 (uuid.equals("") || uuid.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户ID为空,请重新输入!");
   return;
  }
 
  if (name.equals("") || name.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户名为空,请重新输入!");
   return;
  }
 
  if (!pwd.equals(pwd2) || pwd.equals("") || pwd.equals(null)
    || pwd2.equals("") || pwd2.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "两次密码输入不一致或密码为空,请重新输入!");
   return;
  }
  int type = 0;
 
  try {
   type = UserTypeEnum.getTypeByName(combType.getSelectedItem()
     .toString());
  } catch (Exception e) {
   JOptionPane.showMessageDialog(mainFrame, "请指定用户类型!");
   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.update(user)) {
   back();
  } else {
   JOptionPane.showMessageDialog(null, "该用户已经不存在!");
  }
 
 }
 
 private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
  back();
 }
 
 private void back() {
  mainFrame.setContentPane(new ListPanel(mainFrame));
  mainFrame.validate();
 }
 
 // GEN-BEGIN:variables
 // Variables declaration - do not modify
 private javax.swing.JButton btnBack;
 private javax.swing.JButton btnUpdate;
 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
 
}

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
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
/*
 * ListPanel.java
 *
 * Created on __DATE__, __TIME__
 */
 
package cn.hncu.bookStore.user.ui;
 
import java.util.List;
 
import javax.swing.JFrame;
import javax.swing.JOptionPane;
 
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());
 }
 
 //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();
  btnToDelete = new javax.swing.JButton();
  btnToUpdate = 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(170, 80, 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(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\u7528\u6237");
  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\u7528\u6237");
  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\u7528\u6237");
  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);
 }// </editor-fold>
 //GEN-END:initComponents
 
 private void btnToUpdateActionPerformed(java.awt.event.ActionEvent evt) {
  UserModel user = (UserModel) userLists.getSelectedValue();
 
  if (user == null) {
   JOptionPane.showMessageDialog(mainFrame, "请选择要修改的用户!");
   return;
  }
 
  String uuid = user.getUuid();
 
  mainFrame.setContentPane(new UpdatePanel(mainFrame, uuid));
  mainFrame.validate();
 }
 
 private void btnToDeleteActionPerformed(java.awt.event.ActionEvent evt) {
  UserModel user = (UserModel) userLists.getSelectedValue();
 
  if (user == null) {
   JOptionPane.showMessageDialog(mainFrame, "请选择要删除的用户!");
   return;
  }
 
  String uuid = user.getUuid();
 
  mainFrame.setContentPane(new DeletePanel(mainFrame, uuid));
  mainFrame.validate();
 }
 
 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.JButton btnToDelete;
 private javax.swing.JButton btnToUpdate;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JScrollPane jScrollPane1;
 private javax.swing.JList userLists;
 // End of variables declaration//GEN-END:variables
 
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/qq_26525215/article/details/51099202

相关文章

热门资讯

歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意 2019-07-07
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
返回顶部