一、前言
本學(xué)期學(xué)習(xí)了java語言,在學(xué)期的結(jié)束,寫一個(gè)有操作界面,與數(shù)據(jù)庫關(guān)聯(lián)的管理系統(tǒng),用來鞏固自己本學(xué)習(xí)所學(xué)的知識(shí)。
用到的知識(shí):java基礎(chǔ),java界面設(shè)計(jì)(gui),oracle數(shù)據(jù)庫(需要掌握數(shù)據(jù)庫的基本操作語句),鏈接數(shù)據(jù)庫。
使用的開發(fā)工具:myeclipse professional 2014
二、設(shè)計(jì)
我們管理的屬性有:項(xiàng)目編號(hào),項(xiàng)目名稱,參與人員,負(fù)責(zé)人,項(xiàng)目開始時(shí)間,結(jié)束時(shí)間。科研項(xiàng)目系統(tǒng)主要有四個(gè)功能,對(duì)科研項(xiàng)目的增加、刪除、修改、查詢。以及為增加系統(tǒng)安全性所設(shè)計(jì)的登陸模式。
2.1 增加:向數(shù)據(jù)庫的表中增加科研項(xiàng)目的所有信息
添加后在控制臺(tái)使用sql語句查找,驗(yàn)證是否已添加至數(shù)據(jù)庫中。
2.2 查詢:通過具有唯一性的項(xiàng)目編號(hào)查找該項(xiàng)目的所有信息
2.3 修改:根據(jù)項(xiàng)目編號(hào)選中要修改的項(xiàng)目,并重新輸入項(xiàng)目信息進(jìn)行修改
2.4 刪除:通過具有唯一性的項(xiàng)目編號(hào)刪除對(duì)應(yīng)項(xiàng)目的所有信息
三、窗體源碼
3.1 登錄界面
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
|
package 科研信息管理系統(tǒng); import java.awt.*; import java.awt.event.*; import javax.swing.*; public class loginwindows extends frame implements windowlistener,actionlistener { public label lglabel; //用戶名標(biāo)簽 public label pwdlabel; //密碼標(biāo)簽 public textfield lgtext; //用戶名文本框 public textfield pwdtext; //密碼文本框 public button lgbt; //登錄按鈕 public button quitbt; //退出按鈕 public loginwindows() { super (); this .setsize( 400 , 300 ); this .settitle( "科研信息管理系統(tǒng)" ); this .setlayout( null ); lglabel= new label(); lglabel.settext( "登錄賬號(hào):" ); lglabel.setsize( 60 , 30 ); lglabel.setlocation( 70 , 70 ); pwdlabel= new label(); pwdlabel.settext( "密 碼:" ); pwdlabel.setsize( 60 , 30 ); pwdlabel.setlocation( 70 , 150 ); lgtext= new textfield(); lgtext.setsize( 180 , 30 ); lgtext.setlocation( 140 , 70 ); pwdtext= new textfield(); pwdtext.setsize( 180 , 30 ); pwdtext.setlocation( 140 , 150 ); lgbt= new button(); lgbt.setlabel( "登錄" ); lgbt.setsize( 60 , 30 ); lgbt.setlocation( 120 , 220 ); quitbt= new button(); quitbt.setlabel( "退出" ); quitbt.setsize( 60 , 30 ); quitbt.setlocation( 220 , 220 ); quitbt.addactionlistener( this ); lgbt.addactionlistener( this ); this .addwindowlistener( this ); this .add(lglabel); this .add(pwdlabel); this .add(lgtext); this .add(pwdtext); this .add(lgbt); this .add(quitbt); this .setvisible( true ); } public static void main(string args[]) { loginwindows main= new loginwindows(); } @override public void actionperformed(actionevent e) { button bt=(button) e.getsource(); if (bt.getlabel().equals( "退出" )) { system.exit( 0 ); } else { if ((lgtext.gettext().equals( "" ))||(pwdtext.gettext().equals( "" ))) { joptionpane.showmessagedialog( this , "賬號(hào)或密碼為空" ); } else { if ((lgtext.gettext().equals( "admin" ))&&(pwdtext.gettext().equals( "111" ))) //if((lgtext.gettext().equals(""))||(pwdtext.gettext().equals(""))) { this .setvisible( false ); // sqlwindow sql=new sqlwindow(); windowsview w= new windowsview(); w.sciencepro(); } else { joptionpane.showmessagedialog( this , "沒有權(quán)限" ); } }}} @override public void windowopened(windowevent e) { // todo auto-generated method busb } @override public void windowclosing(windowevent e) { // todo auto-generated method busb system.exit( 0 ); } @override public void windowclosed(windowevent e) { // todo auto-generated method busb } @override public void windowiconified(windowevent e) { // todo auto-generated method busb } @override public void windowdeiconified(windowevent e) { // todo auto-generated method busb } @override public void windowactivated(windowevent e) { // todo auto-generated method busb } @override public void windowdeactivated(windowevent e) { // todo auto-generated method busb } } |
3.2主窗體源碼
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
package 科研信息管理系統(tǒng); import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.tree.*; public class windowsview implements treeselectionlistener,actionlistener //窗口類 { jframe main; jpanel leftpa; jpanel uppa; jpanel downpa; ///查詢用控件 jlabel numla; //通過項(xiàng)目編號(hào)查詢 jtextfield numtxt; jbutton numbt; jtextfield nametxt; //顯示項(xiàng)目名稱的文本框 jtextfield peopletxt; //顯示參與人員 jtextfield principaltxt; //顯示主要負(fù)責(zé)人 jtextfield timestarttxt; //顯示開始時(shí)間的文本框 jtextfield timeendtxt; //顯示預(yù)期結(jié)束時(shí)間的文本框 //增加用控件 jlabel anumla; jlabel anamela; jlabel apeoplela; jlabel aprincipalla; jlabel atimestartla; jlabel atimeendla; jtextfield anumtxt; jtextfield anametxt; jtextfield apeopletxt; jtextfield aprincipaltxt; jtextfield atimestarttxt; jtextfield atimeendtxt; jbutton addbt; jtable showtable; //刪除用控件 jlabel dnumla; jbutton dnumbt; jtextfield dnumtxt; //修改用控件 jlabel alnumla; jtextfield allnumtxt; jbutton alsebt; jbutton albt; jlabel allnumla; jlabel alnamela; jlabel alpeoplela; jlabel alprincipalla; jlabel altimestartla; jlabel altimeendla; jtextfield alnumtxt; jtextfield alnametxt; jtextfield alpeopletxt; jtextfield alprincipaltxt; jtextfield altimestarttxt; jtextfield altimeendtxt; public void sciencepro() { main= new jframe(); main.setsize( 800 , 800 ); main.settitle( "科研信息管理" ); main.setlayout( null ); leftpa= new jpanel(); leftpa.setsize( 150 , 600 ); leftpa.setlocation( 0 , 0 ); leftpa.setbackground(color.white); initleftpanel(); main.add(leftpa); uppa= new jpanel(); uppa.setsize( 650 , 400 ); uppa.setlocation( 150 , 0 ); uppa.setbackground(color.gray); main.add(uppa); downpa= new jpanel(); downpa.setsize( 650 , 400 ); downpa.setlocation( 150 , 400 ); downpa.setbackground(color.orange); main.add(downpa); main.setvisible( true ); } private void initleftpanel() { string[] strs={ "查詢" , "增加" , "刪除" , "修改" }; jtree tree= new jtree(strs); tree.addtreeselectionlistener( this ); leftpa.add(tree); } public void valuechanged(treeselectionevent e) { jtree tree=(jtree)e.getsource(); defaultmutabletreenode selectionnode =(defaultmutabletreenode)tree.getlastselectedpathcomponent(); string str=selectionnode.tostring(); if (str.equals( "查詢" )) { initupdownpawhensearch(); } if (str.equals( "增加" )) { initupdownpawhenadd(); } if (str.equals( "刪除" )) { initupdownpawhendelete(); } if (str.equals( "修改" )) { initupdownpawhenalert(); } } private void initupdownpawhensearch() { //清空上下面板上的控件 uppa.removeall(); downpa.removeall(); //動(dòng)態(tài)的加載上面板的控件 uppa.setlayout( null ); numla= new jlabel(); numla.settext( "請(qǐng)輸入項(xiàng)目編號(hào)" ); numla.setlocation( 40 , 60 ); numla.setsize( 100 , 40 ); numtxt= new jtextfield(); numtxt.setlocation( 180 , 60 ); numtxt.setsize( 200 , 30 ); numbt= new jbutton(); numbt.settext( "查詢" ); numbt.addactionlistener( this ); numbt.setlocation( 250 , 160 ); numbt.setsize( 60 , 30 ); uppa.add(numla); uppa.add(numtxt); uppa.add(numbt); uppa.validate(); uppa.repaint(); numbt.addactionlistener( this ); //動(dòng)態(tài)的加載下面板的控件 nametxt= new jtextfield(); nametxt.setlocation( 80 , 50 ); nametxt.setsize( 300 , 30 ); peopletxt= new jtextfield(); peopletxt.setlocation( 80 , 100 ); peopletxt.setsize( 300 , 30 ); principaltxt= new jtextfield(); principaltxt.setlocation( 80 , 150 ); principaltxt.setsize( 300 , 30 ); timestarttxt= new jtextfield(); timestarttxt.setlocation( 80 , 200 ); timestarttxt.setsize( 300 , 30 ); timeendtxt= new jtextfield(); timeendtxt.setlocation( 80 , 250 ); timeendtxt.setsize( 300 , 30 ); downpa.setlayout( null ); downpa.add(nametxt); downpa.add(peopletxt); downpa.add(principaltxt); downpa.add(timestarttxt); downpa.add(timeendtxt); downpa.validate(); downpa.repaint(); } public void actionperformed(actionevent e) { jbutton bt=(jbutton)e.getsource(); //bt.addactionlistener(this); if (bt.gettext().equals( "查詢" )) { if (numtxt.gettext().equals( "" )) { joptionpane.showmessagedialog( null , "請(qǐng)輸入項(xiàng)目編號(hào)" ); } else { dealsearch deal= new dealsearch(); string inf=deal.findprobynum(integer.parseint(numtxt.gettext().trim())); if ((inf!= null )&&(!inf.equals( "" ))) { string[] strs=inf.split( "," ); nametxt.settext(strs[ 1 ]); peopletxt.settext(strs[ 2 ]); principaltxt.settext(strs[ 3 ]); timestarttxt.settext(strs[ 4 ]); timeendtxt.settext(strs[ 5 ]); } } } if (bt.gettext().equals( "新增" )) { if (anumtxt.gettext().equals( "" )||anametxt.gettext().equals( "" )||apeopletxt.gettext().equals( "" )||aprincipaltxt.gettext().equals( "" )||atimestarttxt.gettext().equals( "" )||atimeendtxt.gettext().equals( "" )) { joptionpane.showmessagedialog( null , "輸入中不能有空值!!" ); } else { scienceproject s= new scienceproject(); s.setnum(integer.parseint(anumtxt.gettext())); s.setname(anametxt.gettext()); s.setpeople(apeopletxt.gettext()); s.setleader(aprincipaltxt.gettext()); s.settimestart(atimestarttxt.gettext()); s.settimefinish(atimeendtxt.gettext()); dealadd deal= new dealadd(); deal.add(s); } } if (bt.gettext().equals( "刪除" )) { if (integer.parseint(dnumtxt.gettext())== 0 ) { joptionpane.showmessagedialog( null , "不能刪除空的項(xiàng)目編號(hào)!!" ); } else { dealdelete deal= new dealdelete(); deal.delete(integer.parseint(dnumtxt.gettext().trim())); } } if (bt.gettext().equals( "提交" )) { if (integer.parseint(allnumtxt.gettext())== 0 ) { joptionpane.showmessagedialog( null , "不能修改空的項(xiàng)目編號(hào)!!" ); } else { dealsub deal= new dealsub(); deal.submit(integer.parseint(allnumtxt.gettext())); } } if (bt.gettext().equals( "修改" )) { if (alnametxt.gettext().equals( "" )||alpeopletxt.gettext().equals( "" )||alprincipaltxt.gettext().equals( "" )||altimestarttxt.gettext().equals( "" )||altimeendtxt.gettext().equals( "" )) { joptionpane.showmessagedialog( null , "輸入中不能有空值!!" ); } else { scienceproject s= new scienceproject(); s.setnum(integer.parseint(allnumtxt.gettext())); s.setname(alnametxt.gettext()); s.setpeople(alpeopletxt.gettext()); s.setleader(alprincipaltxt.gettext()); s.settimestart(altimestarttxt.gettext()); s.settimefinish(altimeendtxt.gettext()); dealalter deal= new dealalter(); deal.alter(s); } } } private void initupdownpawhenadd() { //清空上下面板上的控件 uppa.removeall(); downpa.removeall(); //動(dòng)態(tài)的加載上面板的控件 uppa.setlayout( null ); anumla= new jlabel(); anumla.settext( "請(qǐng)輸入要增加的項(xiàng)目編號(hào)" ); anumla.setlocation( 30 , 50 ); anumla.setsize( 150 , 40 ); anumtxt= new jtextfield(); anumtxt.setlocation( 200 , 50 ); anumtxt.setsize( 250 , 30 ); anamela= new jlabel(); anamela.settext( "請(qǐng)輸入要增加的項(xiàng)目名稱" ); anamela.setlocation( 30 , 100 ); anamela.setsize( 150 , 40 ); anametxt= new jtextfield(); anametxt.setlocation( 200 , 100 ); anametxt.setsize( 250 , 30 ); apeoplela= new jlabel(); apeoplela.settext( "請(qǐng)輸入項(xiàng)目參與人員" ); apeoplela.setlocation( 30 , 150 ); apeoplela.setsize( 150 , 40 ); apeopletxt= new jtextfield(); apeopletxt.setlocation( 200 , 150 ); apeopletxt.setsize( 250 , 30 ); aprincipalla= new jlabel(); aprincipalla.settext( "請(qǐng)輸入項(xiàng)目負(fù)責(zé)人" ); aprincipalla.setlocation( 30 , 200 ); aprincipalla.setsize( 150 , 40 ); aprincipaltxt= new jtextfield(); aprincipaltxt.setlocation( 200 , 200 ); aprincipaltxt.setsize( 250 , 30 ); atimestartla= new jlabel(); atimestartla.settext( "請(qǐng)輸入項(xiàng)目開始時(shí)間" ); atimestartla.setlocation( 30 , 250 ); atimestartla.setsize( 150 , 40 ); atimestarttxt= new jtextfield(); atimestarttxt.setlocation( 200 , 250 ); atimestarttxt.setsize( 250 , 30 ); atimeendla= new jlabel(); atimeendla.settext( "請(qǐng)輸入項(xiàng)目結(jié)束時(shí)間" ); atimeendla.setlocation( 30 , 300 ); atimeendla.setsize( 150 , 40 ); atimeendtxt= new jtextfield(); atimeendtxt.setlocation( 200 , 300 ); atimeendtxt.setsize( 250 , 30 ); addbt= new jbutton(); addbt.settext( "新增" ); addbt.addactionlistener( this ); //addbt.addmouselistener(this); addbt.setlocation( 250 , 340 ); addbt.setsize( 60 , 30 ); uppa.add(addbt); uppa.add(anumla); uppa.add(anamela); uppa.add(apeoplela); uppa.add(aprincipalla); uppa.add(atimestartla); uppa.add(atimeendla); uppa.add(anametxt); uppa.add(anumtxt); uppa.add(apeopletxt); uppa.add(aprincipaltxt); uppa.add(atimestarttxt); uppa.add(atimeendtxt); uppa.validate(); uppa.repaint(); downpa.validate(); downpa.repaint(); } private void initupdownpawhendelete() { //清空上下面板上的控件 uppa.removeall(); downpa.removeall(); //動(dòng)態(tài)的加載上面板的控件 uppa.setlayout( null ); numla= new jlabel(); numla.settext( "請(qǐng)輸入要?jiǎng)h除的項(xiàng)目編號(hào)" ); numla.setlocation( 40 , 60 ); numla.setsize( 150 , 40 ); dnumtxt= new jtextfield(); dnumtxt.setlocation( 200 , 60 ); dnumtxt.setsize( 250 , 30 ); dnumbt= new jbutton(); dnumbt.settext( "刪除" ); dnumbt.addactionlistener( this ); dnumbt.setlocation( 270 , 170 ); dnumbt.setsize( 60 , 30 ); uppa.add(numla); uppa.add(dnumtxt); uppa.add(dnumbt); uppa.validate(); uppa.repaint(); downpa.validate(); downpa.repaint(); } private void initupdownpawhenalert() { //清空上下面板上的控件 uppa.removeall(); downpa.removeall(); //動(dòng)態(tài)的加載上面板的控件 uppa.setlayout( null ); alnumla= new jlabel(); alnumla.settext( "請(qǐng)輸入要修改的項(xiàng)目編號(hào)" ); alnumla.setlocation( 40 , 60 ); alnumla.setsize( 150 , 40 ); alsebt= new jbutton(); alsebt.settext( "提交" ); alsebt.addactionlistener( this ); alsebt.setlocation( 270 , 170 ); alsebt.setsize( 60 , 30 ); allnumtxt= new jtextfield(); allnumtxt.setlocation( 200 , 60 ); allnumtxt.setsize( 200 , 30 ); uppa.add(alnumla); uppa.add(alsebt); uppa.add(allnumtxt); uppa.validate(); uppa.repaint(); albt= new jbutton(); albt.settext( "修改" ); albt.addactionlistener( this ); albt.setlocation( 450 , 170 ); albt.setsize( 60 , 30 ); /* allnumla=new jlabel(); allnumla.settext("請(qǐng)輸入修改后的項(xiàng)目編號(hào)"); allnumla.setlocation(30, 00); allnumla.setsize(150, 40); alnumtxt=new jtextfield(); alnumtxt.setlocation(180, 00); alnumtxt.setsize(250, 30);*/ alnamela= new jlabel(); alnamela.settext( "請(qǐng)輸入修改后項(xiàng)目名稱" ); alnamela.setlocation( 30 , 50 ); alnamela.setsize( 150 , 40 ); alnametxt= new jtextfield(); alnametxt.setlocation( 180 , 50 ); alnametxt.setsize( 250 , 30 ); alpeoplela= new jlabel(); alpeoplela.settext( "請(qǐng)重設(shè)參與人員" ); alpeoplela.setlocation( 30 , 100 ); alpeoplela.setsize( 150 , 40 ); alpeopletxt= new jtextfield(); alpeopletxt.setlocation( 180 , 100 ); alpeopletxt.setsize( 250 , 30 ); alprincipalla= new jlabel(); alprincipalla.settext( "請(qǐng)重設(shè)項(xiàng)目負(fù)責(zé)人" ); alprincipalla.setlocation( 30 , 150 ); alprincipalla.setsize( 150 , 40 ); alprincipaltxt= new jtextfield(); alprincipaltxt.setlocation( 180 , 150 ); alprincipaltxt.setsize( 250 , 30 ); altimestartla= new jlabel(); altimestartla.settext( "請(qǐng)重設(shè)項(xiàng)目開始時(shí)間" ); altimestartla.setlocation( 30 , 200 ); altimestartla.setsize( 150 , 40 ); altimestarttxt= new jtextfield(); altimestarttxt.setlocation( 180 , 200 ); altimestarttxt.setsize( 250 , 30 ); altimeendla= new jlabel(); altimeendla.settext( "請(qǐng)重設(shè)項(xiàng)目結(jié)束時(shí)間" ); altimeendla.setlocation( 30 , 250 ); altimeendla.setsize( 150 , 40 ); altimeendtxt= new jtextfield(); altimeendtxt.setlocation( 180 , 250 ); altimeendtxt.setsize( 250 , 30 ); downpa.add(albt); //downpa.add(allnumla); downpa.add(alnamela); downpa.add(alpeoplela); downpa.add(alprincipalla); downpa.add(altimestartla); downpa.add(altimeendla); downpa.add(alnametxt); //downpa.add(alnumtxt); downpa.add(alpeopletxt); downpa.add(alprincipaltxt); downpa.add(altimestarttxt); downpa.add(altimeendtxt); downpa.setlayout( null ); downpa.validate(); downpa.repaint(); } } |
3.3 組織sql語句,鏈接數(shù)據(jù)庫部分
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
|
package 科研信息管理系統(tǒng); import java.sql.*; import java.util.scanner; public class sql { public void addscienceproject(scienceproject scienceproject) { try { class .forname( "oracle.jdbc.driver.oracledriver" ).newinstance(); string constr= "jdbc:oracle:thin:@localhost:1521:xe" ; connection con=drivermanager.getconnection(constr, "system" , "1" ); stringbuffer sql= new stringbuffer( "insert into science values(" +scienceproject.getnum()+ ",'" +scienceproject.getname()+ "','" +scienceproject.getpeople()+ "','" +scienceproject.getleader()+ "','" +scienceproject.gettimestart()+ "','" +scienceproject.gettimefinish()+ "')" ); statement st=con.createstatement(); st.execute(sql.tostring()); st.close(); con.close(); } catch (exception e) { // todo: handle exception system.out.println(e.tostring()); } } public void delscienceproject(scienceproject scienceproject) { try { class .forname( "oracle.jdbc.driver.oracledriver" ).newinstance(); string constr= "jdbc:oracle:thin:@localhost:1521:xe" ; connection con=drivermanager.getconnection(constr, "system" , "1" ); stringbuffer sql= new stringbuffer( "delete from science where num=" +scienceproject.getnum()+ "" ); statement st=con.createstatement(); st.execute(sql.tostring()); st.close(); con.close(); } catch (exception e) { // todo: handle exception system.out.println(e.tostring()); } } public void updscienceproject(scienceproject scienceproject) { try { class .forname( "oracle.jdbc.driver.oracledriver" ).newinstance(); string constr= "jdbc:oracle:thin:@localhost:1521:xe" ; connection con=drivermanager.getconnection(constr, "system" , "1" ); stringbuffer sql = new stringbuffer( "update science set name='" +scienceproject.getname()+ "',workpeople='" +scienceproject.getpeople()+ "',manager='" +scienceproject.getleader()+ "',timestart='" +scienceproject.gettimestart()+ "',timeend='" +scienceproject.gettimefinish()+ "' where num=" +scienceproject.getnum()+ "" ); statement st=con.createstatement(); st.execute(sql.tostring()); st.close(); con.close(); } catch (exception e) { // todo: handle exception system.out.println( "修改異常" ); system.out.println(e.tostring()); } } public scienceproject findbynum( int num) { scienceproject scienceproject= new scienceproject(); try { class .forname( "oracle.jdbc.driver.oracledriver" ).newinstance(); string constr= "jdbc:oracle:thin:@localhost:1521:xe" ; connection con=drivermanager.getconnection(constr, "system" , "1" ); stringbuffer sql= new stringbuffer( "select * from science where num=" +num+ "" ); statement st=con.createstatement(); resultset rs=st.executequery(sql.tostring()); while (rs.next()) { scienceproject.setnum(rs.getint( 1 )); scienceproject.setname(rs.getstring( 2 )); scienceproject.setpeople(rs.getstring( 3 )); scienceproject.setleader(rs.getstring( 4 )); scienceproject.settimestart(rs.getstring( 5 )); scienceproject.settimefinish(rs.getstring( 6 )); } st.close(); con.close(); } catch (exception e) { // todo: handle exception system.out.println(e.tostring()); } return scienceproject; } public scienceproject look() { scienceproject scienceproject= new scienceproject(); try { class .forname( "oracle.jdbc.driver.oracledriver" ).newinstance(); string constr= "jdbc:oracle:thin:@localhost:1521:xe" ; connection con=drivermanager.getconnection(constr, "system" , "1" ); stringbuffer sql= new stringbuffer( "select *from science" ); statement st=con.createstatement(); resultset rs=st.executequery(sql.tostring()); while (rs.next()) { scienceproject.setnum(rs.getint( 1 )); scienceproject.setname(rs.getstring( 2 )); scienceproject.setpeople(rs.getstring( 3 )); scienceproject.setleader(rs.getstring( 4 )); scienceproject.settimestart(rs.getstring( 5 )); scienceproject.settimefinish(rs.getstring( 6 )); } st.close(); con.close(); } catch (exception ex) { // todo: handle exception system.out.println(ex.tostring()); } return scienceproject; } public static void main(string args[]) { } } |
3.4 增刪查改對(duì)應(yīng)處理的源碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
//處理增加 package 科研信息管理系統(tǒng); import javax.swing.joptionpane; public class dealadd { public dealadd() {} public void add(scienceproject s) { sql sql= new sql(); if (sql.findbynum(s.getnum()).getnum()!= 0 ) { joptionpane.showmessagedialog( null , "該項(xiàng)目已存在,請(qǐng)重新輸入!" ); } else { sql.addscienceproject(s); joptionpane.showmessagedialog( null , "增加成功" ); } } } |
由設(shè)計(jì)部分可以看到,刪除時(shí)需要先提交項(xiàng)目編號(hào),所以,需要處理提交事件
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 科研信息管理系統(tǒng); import javax.swing.joptionpane; public class dealsub { dealsub() {} public void submit( int num) { sql sql = new sql(); if (sql.findbynum(num).getnum()== 0 ) { joptionpane.showmessagedialog( null , "不存在該項(xiàng)目" ); } else { joptionpane.showmessagedialog( null , "請(qǐng)?jiān)谙路教顚懶薷暮蟮捻?xiàng)目信息" ); } } } //處理刪除 package 科研信息管理系統(tǒng); import javax.swing.joptionpane; public class dealdelete { public dealdelete() {} public void delete( int num) { scienceproject s= new scienceproject(); sql sql= new sql(); if (sql.findbynum(num).getnum()== 0 ) { joptionpane.showmessagedialog( null , "不存在該項(xiàng)目~" ); } else { s=sql.findbynum(num); sql.delscienceproject(s); joptionpane.showmessagedialog( null , "刪除成功~" ); } } } //處理修改 package 科研信息管理系統(tǒng); import javax.swing.joptionpane; public class dealalter { public dealalter() {} public void alter(scienceproject s) { sql sql= new sql(); sql.updscienceproject(s); joptionpane.showmessagedialog( null , "修改成功" ); } } //處理查詢 package 科研信息管理系統(tǒng); public class dealsearch //處理查詢事件 { public dealsearch() {} public string findprobynum( int num) //通過項(xiàng)目編號(hào)查詢 { string result= "" ; scienceproject s= new scienceproject(); sql sql= new sql(); s=sql.findbynum(num); result=s.getnum()+ "," +s.getname()+ "," +s.getpeople()+ "," +s.getleader()+ "," +s.gettimestart()+ "," +s.gettimefinish(); return result; } } |
3.5 主函數(shù)調(diào)用登錄窗口
1
2
3
4
5
6
7
8
9
10
11
|
package 科研信息管理系統(tǒng); public class test { public static void main(string[] args) { loginwindows v= new loginwindows(); } } |
四、總結(jié)
還是有一些的缺陷存在的,由于對(duì)科研項(xiàng)目的不熟悉,有些屬性設(shè)計(jì)得不合理,還有很多沒有考慮到的地方,另外對(duì)gui的不熟悉也限制了我們?cè)诖翱谏系脑O(shè)計(jì)。還需要在項(xiàng)目屬性及窗口等方面進(jìn)行修改。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:http://blog.csdn.net/pointer_y/article/details/54381545