服务器之家

服务器之家 > 正文

图书信息管理java实现代码

时间:2021-03-24 14:10     来源/作者:晓晓jsw

图书信息管理与读者信息管理相似,共包括两部分,图书添加和图书查询与修改,图书信息添加要求正确输入图书的八项信息,并且isbn编号唯一,实现过程中要将isbn作为主键。下面看实现过程:

数据库中书籍:

图书信息管理java实现代码

添加书籍过程:

图书信息管理java实现代码

数据库内容增加:

图书信息管理java实现代码

 

图书的查询与修改:查询过程可以根据不同的条件查询,如isbn,作者,出版社,图书名称等,默认将所有图书全部显示在列表中,输入查询条件后再表格中显示查询结果。

本模块用到标签面板,可以很方便的查询所需要的信息。修改过程输入isbn编号后按回车键将在下方显示所有的图书信息,然后修改图书信息后所有内容就会更新。

图书查询:

图书信息管理java实现代码

图书信息修改:

图书信息管理java实现代码

添加图书源代码如下:addbook.java

?
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
package pdsu.bbm.view;
 
import java.awt.borderlayout;
import java.awt.flowlayout;
import java.awt.font;
import java.awt.image;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import java.text.parseexception;
import java.text.simpledateformat;
import java.util.date;
import java.util.iterator;
import java.util.list;
import javax.swing.buttongroup;
import javax.swing.imageicon;
import javax.swing.jbutton;
import javax.swing.jcombobox;
import javax.swing.jframe;
import javax.swing.jlabel;
import javax.swing.joptionpane;
import javax.swing.jpanel;
import javax.swing.jtextfield;
import pdsu.bbm.dao.bookdao;
import pdsu.bbm.dao.booktypedao;
import pdsu.bbm.model.book;
import pdsu.bbm.model.booktype;
public class addbook extends jframe implements actionlistener {
 
 private jpanel contentpane;
 private jlabel label_1;
 private jlabel lbll;
 private jlabel label_2;
 private jlabel label_3;
 private jlabel label_4;
 private jlabel label_5;
 jpanel centerppanel;
 jbutton button1, button2, button3;
 private jcombobox combobox_1;
 image icon = new imageicon("image/icon.png").getimage();
 private jtextfield isbnfiled;
 private jtextfield publishfield;
 private jtextfield publishdatefield;
 private jtextfield publishtime;
 private jtextfield unitpricefield;
 private jtextfield booknamefield;
 private jtextfield authorfiled;
 public static void main(string[] args) {
 new addbook();
 }
 public addbook() {
 settitle("添加图书信息");
 setsize(555, 333);
 seticonimage(icon);
 setlocationrelativeto(null);
 
 settitle("添加图书信息");
 setsize(555, 334);
 setlocationrelativeto(null);
 setvisible(true);
 centerppanel = new jpanel();
 centerppanel.setlayout(null);
 jlabel label1 = new jlabel("isbn:");
 label1.setfont(new font("宋体", font.plain, 20));
 label1.setbounds(71, 26, 95, 42);
 centerppanel.add(label1);
 
 isbnfiled = new jtextfield();
 isbnfiled.setbounds(120, 30, 110, 30);
 centerppanel.add(isbnfiled);
 isbnfiled.setcolumns(10);
 
 jlabel label = new jlabel("类 别:");
 label.setfont(new font("宋体", font.plain, 20));
 label.setbounds(306, 30, 116, 35);
 centerppanel.add(label);
 
 label_1 = new jlabel("书 名:");
 label_1.setfont(new font("宋体", font.plain, 20));
 label_1.setbounds(50, 75, 154, 50);
 centerppanel.add(label_1);
 
 lbll = new jlabel("作 者:");
 lbll.setfont(new font("宋体", font.plain, 20));
 lbll.setbounds(306, 75, 137, 50);
 centerppanel.add(lbll);
 
 label_2 = new jlabel("出版社:");
 label_2.setfont(new font("宋体", font.plain, 20));
 label_2.setbounds(50, 130, 154, 50);
 centerppanel.add(label_2);
 
 label_3 = new jlabel("出版日期:");
 label_3.setfont(new font("宋体", font.plain, 20));
 label_3.setbounds(285, 135, 137, 50);
 centerppanel.add(label_3);
 
 publishfield = new jtextfield();
 publishfield.setcolumns(10);
 publishfield.setbounds(120, 143, 110, 30);
 centerppanel.add(publishfield);
 
 publishdatefield = new jtextfield();
 publishdatefield.setcolumns(10);
 publishdatefield.setbounds(380, 143, 120, 30);
 centerppanel.add(publishdatefield);
 
 label_4 = new jlabel("印刷次数:");
 label_4.setfont(new font("宋体", font.plain, 20));
 label_4.setbounds(28, 190, 154, 50);
 centerppanel.add(label_4);
 
 publishtime = new jtextfield();
 publishtime.setcolumns(10);
 publishtime.setbounds(120, 203, 110, 30);
 centerppanel.add(publishtime);
 
 label_5 = new jlabel("单 价:");
 label_5.setfont(new font("宋体", font.plain, 20));
 label_5.setbounds(305, 194, 84, 42);
 centerppanel.add(label_5);
 
 unitpricefield = new jtextfield();
 unitpricefield.setcolumns(10);
 unitpricefield.setbounds(380, 203, 120, 30);
 centerppanel.add(unitpricefield);
 getcontentpane().add(centerppanel, borderlayout.center);
 
 booknamefield = new jtextfield();
 booknamefield.setcolumns(10);
 booknamefield.setbounds(120, 86, 110, 30);
 centerppanel.add(booknamefield);
 
 authorfiled = new jtextfield();
 authorfiled.setcolumns(10);
 authorfiled.setbounds(380, 86, 120, 30);
 centerppanel.add(authorfiled);
 
 list<booktype> rs = booktypedao.selectbooktype();
 iterator<booktype> iterator = rs.iterator();
 string[] alltypename = new string[rs.size()];
 int i = 0;
 while (iterator.hasnext()) {
  string typename = iterator.next().gettypename();
  alltypename[i] = typename;
  i++;
 }
 combobox_1 = new jcombobox(alltypename);
 combobox_1.setbounds(380, 30, 120, 30);
 combobox_1.setfont(new font("宋体", font.plain, 16));
 
 centerppanel.add(combobox_1);
 buttongroup group = new buttongroup();
 jpanel panel2 = new jpanel();
 panel2.setlayout(new flowlayout());
 button1 = new jbutton("添加");
 button1.setfont(new font("宋体", font.plain, 20));
 
 button2 = new jbutton("关闭");
 button2.setfont(new font("宋体", font.plain, 20));
 button3 = new jbutton("重置");
 button3.setfont(new font("宋体", font.plain, 20));
 
 panel2.add(button1);
 panel2.add(button3);
 panel2.add(button2);
 button1.addactionlistener(this);
 button2.addactionlistener(this);
 button3.addactionlistener(this);
 getcontentpane().add(panel2, borderlayout.south);
 
 setvisible(true);
 }
 
 @suppresswarnings("unused")
 public void actionperformed(actionevent e) {
 if (e.getsource() == button1) {
  string isbn = isbnfiled.gettext().tostring();
 
  string bookname = booknamefield.gettext();
  string author = authorfiled.gettext();
  string selecttype = combobox_1.getselecteditem().tostring();
  string publish = publishfield.gettext();
  string publishdate = publishdatefield.gettext();
  string time = publishtime.gettext().trim();
  string price = unitpricefield.gettext().trim();
 
  if (isbn.equals("") || bookname.equals("") || author.equals("")
   || selecttype.equals("") || publish.equals("")
   || publishdate.equals("") || time.equals("")
   || price.equals("")) {
  joptionpane.showmessagedialog(this, "请输入完整信息");
  return;
  } else {
  booktype bt = new booktype();
  book book = new book();
  book.setisbn(isbn);
  book.setbookname(bookname);
  book.setauthor(author);
  bt.settypename(selecttype);
  int m = 0;
  list<booktype> list = booktypedao
   .selectidbytypename(selecttype);
  iterator<booktype> ite = list.iterator();
  while (ite.hasnext()) {
   m = ite.next().getid();
  }
  book.settypeid(m + "");
  book.setpublish(publish);
  try {
   book.setpublishtime(integer.parseint(time));
   book.setunitprice(integer.parseint(price));
  } catch (numberformatexception e1) {
   e1.printstacktrace();
  }
   
   simpledateformat sdf = new simpledateformat("yyyy-mm-dd");
   date regdate = null;
   try {
   regdate =sdf.parse(publishdate);
   } catch (parseexception e1) {
   joptionpane.showmessagedialog(this, "请输入正确的日期");
   publishdatefield.settext("");
   }
   
   book.setpublishdate(regdate);
  if(regdate==null) return;
   
   if (bookdao.selectbookbyisbn(isbn) != null) {
   joptionpane.showmessagedialog(this, "该isbn编号已存在");
   return;
  } else if (bookdao.insertbook(book) != 0) {
   joptionpane.showmessagedialog(this, "添加成功");
  } else
   joptionpane.showmessagedialog(this, "添加失败");
  }
 }
 if (e.getsource() == button3) {
  isbnfiled.settext("");
  booknamefield.settext("");
  authorfiled.settext("");
  publishfield.settext("");
  publishdatefield.settext("");
  publishtime.settext("");
  unitpricefield.settext("");
 }
 if (e.getsource() == button2) {
  dispose();
  new mainwindow();
 
 }
 }
 
}

图书查询与修改源代码:bookselectandmodify.java

?
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package pdsu.bbm.view;
 
import java.awt.borderlayout;
import java.awt.dimension;
import java.awt.font;
import java.awt.gridlayout;
import java.awt.image;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import java.text.simpledateformat;
import java.util.arraylist;
import java.util.date;
import java.util.iterator;
import java.util.list;
import javax.swing.imageicon;
import javax.swing.jbutton;
import javax.swing.jcombobox;
import javax.swing.jframe;
import javax.swing.jlabel;
import javax.swing.joptionpane;
import javax.swing.jpanel;
import javax.swing.jscrollpane;
import javax.swing.jtabbedpane;
import javax.swing.jtable;
import javax.swing.jtextfield;
import javax.swing.swingconstants;
import javax.swing.table.tablemodel;
import pdsu.bbm.dao.bookdao;
import pdsu.bbm.dao.booktypedao;
import pdsu.bbm.model.book;
import pdsu.bbm.model.booktype;
 
public class bookselectandmodify extends jframe implements actionlistener {
 // 设置序列号
 private static final long serialversionuid = 1l;
 private jtabbedpane jtabbedpane; // 标签面板
 // selectjp查询面板 select_conditionjp下拉列表面板 select_resultjp结果按钮面板updatejp修改面板
 // updatejp修改面板,bookjp中间面板 buttonjp2按钮面板
 private jpanel selectjp, select_conditionjp, select_resultjp, buttonjp1,
  bookjp, updatejp, buttonjp2;//
 private jtextfield selectjtf, isbnjtf, booknamejtf, authorjtf,
  printtimejtf, publishjtf, publishdatejtf, unitpricejtf;
 private jlabel isbnjl, booknamejl, authorjl, categoryjl, printtimejl,
  publishjl, publishdatejl, unitpricejl;
 // 重点!
 private jtable jtable;// 定义表格
 private jcombobox choicejcb, booktypejcb;
 private jscrollpane jscrollpane;
 private jbutton selectjb, exitjb, updatejb, resetjb;// 查询按钮,退出按钮,修改按钮,关闭按钮
 private tablemodel getselect;
 private string[] title = { "isbn", "图书序列", "图书名称", "作者", " 出版社 ",
  "出版日期", "印刷次数", "单价" };
 image icon = new imageicon("image/icon.png").getimage();
 
 public bookselectandmodify() {
 super();
 seticonimage(icon);
 settitle("图书查询与修改");
 setbounds(100, 100, 555, 400);
 setlocationrelativeto(null);
 // jtabbedpane选项卡
 jtabbedpane = new jtabbedpane();
 add(jtabbedpane);
 selectjp = new jpanel();
 selectjp.setlayout(new borderlayout());
 jtabbedpane.add("图书信息查询", selectjp);
 
 // 查询条件面板
 select_conditionjp = new jpanel();
 choicejcb = new jcombobox();
 string array[] = { "isbn", "图书名称", "图书序列", "作者", "出版社","所有" };// 设置为一维数组
 for (int i = 0; i < array.length; i++) {
  choicejcb.additem(array[i]);
 }
 select_conditionjp.add(choicejcb);
 selectjtf = new jtextfield(20);
 select_conditionjp.add(selectjtf);
 selectjp.add(select_conditionjp, borderlayout.north);
 // 查询结果面板
 select_resultjp = new jpanel();
 bookdao dao = new bookdao();
 list<book> list = dao.selectbook();
 jtable = new jtable(getselect(list), title);
 
 // !设置表格大小不变
 jtable.setautoresizemode(jtable.auto_resize_off);
 // !设置列宽
 jtable.getcolumnmodel().getcolumn(4).setpreferredwidth(175);
 jscrollpane = new jscrollpane(jtable);// 把表格加入滚动面板
 // 显示滚动面板边框
 jscrollpane.setpreferredsize(new dimension(450, 170));
 select_resultjp.add(jscrollpane);
 selectjp.add(select_resultjp, borderlayout.center);
 // 查询按钮面板
 buttonjp1 = new jpanel();
 selectjb = new jbutton("查询");
 selectjb.setfont(new font("宋体", font.plain, 20));
 
 selectjb.addactionlistener(this);
 buttonjp1.add(selectjb);
 exitjb = new jbutton("退出");
 exitjb.setfont(new font("宋体", font.plain, 20));
 exitjb.addactionlistener(this);
 buttonjp1.add(exitjb);
 selectjp.add(buttonjp1, borderlayout.south);
 // 信息修改页面
 updatejp = new jpanel();
 updatejp.setlayout(new borderlayout());
 jtabbedpane.addtab("图书信息修改", updatejp);
 bookjp = new jpanel();
 final gridlayout gridlayout = new gridlayout(8, 2);
 // 设置边框间的距离
 gridlayout.setvgap(8);
 gridlayout.sethgap(8);
 bookjp.setlayout(gridlayout);
 isbnjl = new jlabel("isbn:");
 isbnjl.setfont(new font("宋体",font.plain,20));
 isbnjl.sethorizontalalignment(swingconstants.center);
 bookjp.add(isbnjl);
 isbnjtf = new jtextfield(20);
 isbnjtf.addactionlistener(this);
 bookjp.add(isbnjtf);
 categoryjl = new jlabel("类 别:");
 categoryjl.setfont(new font("宋体",font.plain,20));
 categoryjl.sethorizontalalignment(swingconstants.center);
 bookjp.add(categoryjl);
 // 下拉列表
 list<booktype> list1 = booktypedao.selectbooktype();
 iterator<booktype> it = list1.iterator();
 string ty[] = new string[list1.size()];
 int i = 0;
 booktypejcb = new jcombobox();
 while (it.hasnext()) {
  ty[i] = it.next().gettypename();
  booktypejcb.additem(ty[i]);
  i++;
 }
 
 bookjp.add(booktypejcb);
 
 booknamejl = new jlabel("书 名:");
 booknamejl.setfont(new font("宋体",font.plain,20));
 booknamejl.sethorizontalalignment(swingconstants.center);
 bookjp.add(booknamejl);
 booknamejtf = new jtextfield();
 booknamejtf.setcolumns(20);
 bookjp.add(booknamejtf);
 
 authorjl = new jlabel("作 者:");
 authorjl.setfont(new font("宋体",font.plain,20));
 authorjl.sethorizontalalignment(swingconstants.center);
 bookjp.add(authorjl);
 authorjtf = new jtextfield();
 authorjtf.setcolumns(20);
 bookjp.add(authorjtf);
 
 publishjl = new jlabel("出版社:");
 publishjl.setfont(new font("宋体",font.plain,20));
 publishjl.sethorizontalalignment(swingconstants.center);
 bookjp.add(publishjl);
 publishjtf = new jtextfield();
 bookjp.add(publishjtf);
 
 publishdatejl = new jlabel("出版日期:");
 publishdatejl.setfont(new font("宋体",font.plain,20));
 publishdatejl.sethorizontalalignment(swingconstants.center);
 bookjp.add(publishdatejl);
 publishdatejtf = new jtextfield();
 publishdatejtf.sethorizontalalignment(swingconstants.left);
 bookjp.add(publishdatejtf);
 
 printtimejl = new jlabel("印刷次数:");
 printtimejl.setfont(new font("宋体",font.plain,20));
 printtimejl.sethorizontalalignment(swingconstants.center);
 bookjp.add(printtimejl);
 printtimejtf = new jtextfield();
 bookjp.add(printtimejtf);
 
 unitpricejl = new jlabel("单 价:");
 unitpricejl.setfont(new font("宋体",font.plain,20));
 unitpricejl.sethorizontalalignment(swingconstants.center);
 bookjp.add(unitpricejl);
 unitpricejtf = new jtextfield();
 bookjp.add(unitpricejtf);
 // 按钮面板
 // 按钮面板设计
 buttonjp2 = new jpanel();
 updatejb = new jbutton("修改");
 updatejb.setfont(new font("宋体", font.plain, 20));
 
 updatejb.addactionlistener(this);
 resetjb = new jbutton("关闭");
 resetjb.setfont(new font("宋体", font.plain, 20));
 
 resetjb.addactionlistener(this);
 buttonjp2.add(updatejb);
 buttonjp2.add(resetjb);
 updatejp.add(bookjp, borderlayout.center);
 updatejp.add(buttonjp2, borderlayout.south);
 setvisible(true);
 setdefaultcloseoperation(jframe.exit_on_close);
 }
 
 // 将查询表格加入面板
 private object[][] getselect(list<book> list) {
 // todo auto-generated method stub
 object[][] objects = new object[list.size()][title.length];
 for (int i = 0; i < list.size(); i++) {
  book book = list.get(i);
  objects[i][0] = book.getisbn();
  objects[i][1] = book.gettypeid();// 图书序列
  objects[i][2] = book.getbookname();// 图书名称
  objects[i][3] = book.getauthor();// 图书作者
  objects[i][4] = book.getpublish();// 出版社
  objects[i][5] = book.getpublishdate();// 出版日期
  objects[i][6] = book.getpublishtime();// 印刷次数
  objects[i][7] = book.getunitprice();// 单价
 }
 
 return objects;
 
 }
 public void actionperformed(actionevent e) {
 // todo auto-generated method stub
 if(e.getsource()==isbnjtf){
  string isbn=isbnjtf.gettext();
  string typename=null;
  string id=bookdao.selectbookbyisbn(isbn).gettypeid();
  
  typename=booktypedao.selectbyid(id);
  system.out.println(typename);
  booktypejcb.setselecteditem(typename);
  booknamejtf.settext(bookdao.selectbookbyisbn(isbn).getbookname());
  authorjtf.settext(bookdao.selectbookbyisbn(isbn).getauthor());
  publishjtf.settext(bookdao.selectbookbyisbn(isbn).getpublish());
  publishdatejtf.settext(bookdao.selectbookbyisbn(isbn).getpublishdate()+"");
  printtimejtf.settext(bookdao.selectbookbyisbn(isbn).getpublishtime()+"");
  unitpricejtf.settext(bookdao.selectbookbyisbn(isbn).getunitprice()+"");
  
 }
 if (e.getsource() == selectjb) {// 按照isbn编码查找
  int r = choicejcb.getselectedindex();
  if (r == 0) {
  string name = selectjtf.gettext().trim();
  // 强制转换为线性表类型
  list<book> list = new arraylist<book>();
  book book = bookdao.selectbookbyisbn(name);
  if (book == null) {
   joptionpane.showmessagedialog(this, "该编码不存在!");
  } else {
   list.add(book);
   object[][] data = getselect(list);
   jtable = new jtable(data, title);
   jtable.getcolumnmodel().getcolumn(4).setpreferredwidth(175);
   jtable.setautoresizemode(jtable.auto_resize_off);
 
   jscrollpane.setviewportview(jtable);
 
  }
  }
 
  if (r == 1) {// 根据图书名称查询信息
  string name = selectjtf.gettext().tostring();
  list<book> list = bookdao.selectbookbyname(name);
  // 判断线性表是否为空
  if (list == null || list.size() == 0) {
   joptionpane.showmessagedialog(this, "该图书不存在!");
  } else {
   object[][] data = getselect(list);
   jtable = new jtable(data, title);
   tianjia();
  }
  }
  if (r == 2) {// 根据图书序列查询信息
  string name = selectjtf.gettext().tostring();
  list<book> list = bookdao.selectbookbytype(name);
  // 判断线性表是否为空
  if (list == null || list.size() == 0) {
   joptionpane.showmessagedialog(this, "该图书不存在!");
  } else {
   object[][] data = getselect(list);
   jtable = new jtable(data, title);
   tianjia();
  }
  }
  if (r == 3) { // 根据作者进行查找
  string name = selectjtf.gettext().tostring();
  // 根据作者进行查找
  list<book> list = bookdao.selectbookbyauthor(name);
  // 判断线性表是否为空
  if (list == null || list.size() == 0) {
   joptionpane.showmessagedialog(this, "该图书不存在!");
  } else {
   object[][] data = getselect(list);
   jtable = new jtable(data, title);
   tianjia();
  }
  }
  if (r == 4) {// 根据出版社进行查找
  string name = selectjtf.gettext().tostring();
  list<book> list = bookdao.selectbookbypublish(name);
  if (list == null || list.size() == 0) {
   joptionpane.showmessagedialog(this, "该图书不存在!");
  } else {
   object[][] data = getselect(list);
   jtable = new jtable(data, title);
   tianjia();
 
  }
  }
  if(r==5){
  list<book> list =bookdao.selectbook();
  }
 }
 if (e.getsource() == updatejb) {
  string isbn = isbnjtf.gettext().trim();
  string typename = ((string) booktypejcb.getselecteditem()).trim();
  string id = booktypedao.selectbytypename(typename);
  string bookname = booknamejtf.gettext();
  string author = authorjtf.gettext();
  string publish = publishjtf.gettext();
  string publishdate = publishdatejtf.gettext();
 
  simpledateformat sdf = new simpledateformat("yyyy-mm-dd");
  date regdate = null;
  try {
  regdate = sdf.parse(publishdate);
  } catch (exception e2) {
  e2.printstacktrace();
  joptionpane.showmessagedialog(this, "请输入正确的日期格式!");
  }
  if (regdate == null)
  return;
  int publishtime = integer.parseint(printtimejtf.gettext());
  int unitprice = integer.parseint(unitpricejtf.gettext());
  // 封装对象
  book book = new book();
  book.setisbn(isbn);
  book.settypeid(id);
  book.setbookname(bookname);
  book.setauthor(author);
  book.setpublish(publish);
  book.setpublishdate(regdate);
  book.setpublishtime(publishtime);
  book.setunitprice(unitprice);
  book.settypename(typename);
  int result = bookdao.update(book);
  list<book> list2 = new arraylist<book>();
  list2.add(book);
 
  // system.out.println(list2);
 
  if (result == 1) {
  joptionpane.showmessagedialog(this, "修改成功!");
  bookdao bk=new bookdao();
  list<book> list =bk.selectbook();
  jtable =new jtable(getselect(list),title);
  tianjia();
   
  } else {
  joptionpane.showmessagedialog(this, "修改失败!");
  }
 }
 if (e.getsource() == resetjb) {
  dispose();
  new mainwindow();
 }
 if (e.getsource() == exitjb) {
  dispose();
  new mainwindow();
 }
 }
 
 private void tianjia() {
 jtable.getcolumnmodel().getcolumn(4).setpreferredwidth(175);
 jtable.setautoresizemode(jtable.auto_resize_off);
 
 jscrollpane.setviewportview(jtable);
 
 }
 
 public static void main(string[] args) {
 new bookselectandmodify();
 
 }
}

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

原文链接:http://blog.csdn.net/MyLove621/article/details/54834819

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部