java通讯录.docx
《java通讯录.docx》由会员分享,可在线阅读,更多相关《java通讯录.docx(32页珍藏版)》请在冰豆网上搜索。
java通讯录
目录
一、设计目的……………………………………………………………………………………1
二、功能介绍……………………………………………………………………………………2
三、程序流程……………………………………………………………………………………2
四、设计步骤……………………………………………………………………………………3
五、设计总结……………………………………………………………………………………7
六、程序清单……………………………………………………………………………………10
七、参考文献……………………………………………………………………………………25
一、设计目的
通过课程设计,提高理论和实际相结合来解决实际问题的能力,也使自己对基于面向对象的理论进行系统设计过程中的诸多具体问题有感性的认识和深入的理解,进而提高自己的学习兴趣为将来顺利进入毕业环节做必要的准备。
二、功能介绍
(1)具有新用户注册功能。
(2)具有注册用户登录功能。
(3)具有数据的录入功能。
(4)具有数据查询功能,可以实现查询全部信息和按条件执行查询。
(5)具有按条件删除数据功能。
(6)具有统计功能
三、程序流程
四、设计步骤
登录界面
publicLogin(Displaydisplay,intstyle){
super(display,style);
setImage(org.eclipse.wb.swt.ResourceManager.getPluginImage("zui","icons/13.gif"));
createContents();
setBackgroundImage(ResourceManager.getPluginImage(Activator.getDefault(),"icons/2372629_224209091_2.jpg"));
setBackgroundMode(SWT.INHERIT_DEFAULT);
}
创建一个view1类作为工具栏
publicvoidcreatePartControl(Compositeparent){
Compositecontainer=newComposite(parent,SWT.NONE);
ButtonbtnNewButton=newButton(container,SWT.BORDER);
btnNewButton.addSelectionListener(newSelectionAdapter(){
}
新名片录入类Luru,包括人名,年龄,电话,属相,星座的录入,点击提交按钮把数据导入数据库。
publicvoidwidgetSelected(SelectionEvente){
//将信息存入数据库
Stringsql="insertintotongxun(name,age,tel,shuxiang,xingzuo)"+
"values"+"('"+text.getText()+"','"+text_1.getText()+"','"+text_2.getText()+"','"+text_3.getText()+"','"+text_4.getText()+"')";
System.out.println(sql);
DBHelperdb=newDBHelper();
db.update(sql);
publicvoidwidgetSelected(SelectionEvente){
//选择操作行,右键点修改弹出shell
TableItem[]items=table.getSelection();
if(items.length==0){
MessageDialog.openInformation(RUtil.getShell(),"操作有误",
"请选择要修改的行!
");
}else{
TableItemitem=items[0];
Stringname=item.getText(0);
try{
Displaydisplay=Display.getDefault();
Xiugaishell=newXiugai(display,
SWT.SHELL_TRIM);
shell.open();
shell.layout();
shell.fillText(name);
while(!
shell.isDisposed()){
if(!
display.readAndDispatch())
display.sleep();
}
}catch(Exceptione1){
e1.printStackTrace();
}
}
}
});
创建的查询类chaxun,可以按条件查询,按姓名查询,按星座查询,按电话查询,及统计所有联系人,查询出的联系人在表格中显示,右键单击所要修改或删除的人的信息,会弹出修改窗口如下
创建一个修改类Xiugai,所选择的联系人按右键修改此人信息,按确定键提交入数据库。
publicvoidwidgetSelected(SelectionEvente){
Stringname=text.getText();
Stringage=text_1.getText();
Stringtel=text_2.getText();
Stringshuxiang=text_3.getText();
Stringxingzuo=text_4.getText();
if(name.equals("")){
MessageDialog.openInformation(RUtil.getShell(),"信息不能为空","数据不能为空!
");
return;
}
新用户注册类Zhuce,按确定键提交入数据库。
五、设计总结
此次课程设计做完之后,对自己的实际操作能力起到了提高,比较理想地完成了课程设计所要求的所有任务。
我觉得需求分析是很重要的,就拿这次的题目来说,一个清晰的需求分析能让我省去很多工作,能让我把代码写的更清晰,让我的代码能有更好的重用性,以此简化程序。
而这次的题目其实也算不上需求分析,只能算是功能分析吧。
从界面到用户登陆判断,从增删改查基本功能到文件读写。
如果能够把代码细化,把基本功能都封装成函数,这样应该会提高代码的重用性。
另外程序虽然完成了所有功能,但是还具有不严密性,易出错性,在今后应该更加丰富自己的知识,把程序写得更加完美。
六、程序清单
查询类:
packageeditors;
importjava.sql.ResultSet;
importorg.eclipse.core.runtime.IProgressMonitor;
importorg.eclipse.jface.dialogs.MessageDialog;
importorg.eclipse.swt.SWT;
importorg.eclipse.swt.widgets.Composite;
importorg.eclipse.ui.IEditorInput;
importorg.eclipse.ui.IEditorSite;
importorg.eclipse.ui.PartInitException;
importorg.eclipse.ui.part.EditorPart;
importorg.eclipse.swt.widgets.Display;
importorg.eclipse.swt.widgets.Label;
importorg.eclipse.swt.widgets.Text;
importorg.eclipse.swt.widgets.Button;
importorg.eclipse.swt.widgets.Table;
importorg.eclipse.swt.widgets.TableItem;
importorg.eclipse.swt.widgets.TableColumn;
importorg.eclipse.swt.events.SelectionAdapter;
importorg.eclipse.swt.events.SelectionEvent;
importcommon.DBHelper;
importcommon.RUtil;
importorg.eclipse.swt.widgets.Menu;
importorg.eclipse.swt.widgets.MenuItem;
publicclassChaxunextendsEditorPart{
publicstaticfinalStringID="editors.Chaxun";//$NON-NLS-1$
privateTexttext;
privateTexttext_1;
privateTabletable;
privateTexttext_2;
publicChaxun(){
}
/**
*Createcontentsoftheeditorpart.
*@paramparent
*/
@Override
publicvoidcreatePartControl(Compositeparent){
Compositecontainer=newComposite(parent,SWT.NONE);
LabellblNewLabel=newLabel(container,SWT.NONE);
lblNewLabel.setBounds(117,58,88,18);
lblNewLabel.setText("\u6309\u59D3\u540D\u67E5\u627E");
Labellblid=newLabel(container,SWT.NONE);
lblid.setText("\u6309\u661F\u5EA7\u67E5\u627E");
lblid.setBounds(117,93,88,18);
Labellabel_1=newLabel(container,SWT.NONE);
label_1.setText("\u6309\u7535\u8BDD\u67E5\u627E");
label_1.setBounds(117,130,88,18);
text=newText(container,SWT.BORDER);
text.setBounds(214,58,88,18);
text_1=newText(container,SWT.BORDER);