1、Java大作业同学通信录管理完整整理Java程序设计学生通讯录系统设计计算机Z1111班:张志虎、葛志强2013/12/21同学通信录管理系统一、功能要求:1、信息录入,包括记录的追加和插入; 2、信息删除;3、信息修改;4、信息排序和查询;5、信息的保存和装载;6、简单的帮助。 系统开发目录:图2-1:系统开发目录二、用例图图2-1:系统用例图三、类图图3-1:系统类图书四、截图及核心代码1、登录模块功能介绍:实现用户的登陆,还包含注册账号和找回密码两个功能。同时可以实现记住密码、自动登陆。界面展示:图4-1 系统登录核心代码:tryString name=cobUserName.getSe
2、lectedItem().toString()。/获取用户输入的用户名/输入用户名是否为空if(name.equals()JOptionPane.showMessageDialog(null,用户名不能为空!,登录失败,JOptionPane.INFORMATION_MESSAGE)。String password=new String(txtPassword.getPassword().trim()。/获取用户输入的密码/输入密码是否为空if(password.equals()JOptionPane.showMessageDialog(null,密码不能为空!,登录失败,JOptionPan
3、e.INFORMATION_MESSAGE)。return。boolean isMemoryPWD= chbMemoryPWD.isSelected()。boolean isAutoLogon=chbAutoLogon.isSelected()。/System.out.println(isMemoryPWD)。User user =new User(name,password)。if(user.userLogon()/用户是否存在UserProperty userp=new UserProperty(user,isMemoryPWD,isAutoLogon)。ReadWriteProperti
4、es.writeProperties(userp)。dispose()。MainFrame mainframe=new MainFrame(user)。/启动主操作界面mainframe.setVisible(true)。else/提示失败信息JOptionPane.showMessageDialog(null,用户名或密码输入有误!,登录成功,JOptionPane.INFORMATION_MESSAGE)。cobUserName.setFocusable(true)。/输入用户名的控件获得焦点txtPassword.setText(null)。/输入密码的控件为空catch(Excepti
5、on e) 登录界面-账号注册功能介绍:注册用户界面展示:图4-2 系统用户注册核心代码:public void userRegist()String username=txtUserName.getText().trim()。String password=new String(txtpassword.getPassword().trim()。String passwordok=new String(txtPasswordOk.getPassword()。String id=txtId.getText().trim()。/用户名不能为空if(username.isEmpty()/提示信息JO
6、ptionPane.showMessageDialog(null,用户名不能为空!,用户注册,JOptionPane.INFORMATION_MESSAGE)。return 。/用户名为518if(username.length()18)/提示信息JOptionPane.showMessageDialog(null,用户名长度应在518之间!,用户注册,JOptionPane.INFORMATION_MESSAGE)。return 。User user=new User(username,password,id)。try if(user.userRegist()/提示失败信息JOptionPa
7、ne.showMessageDialog(null,注册成功!,注册成功,JOptionPane.INFORMATION_MESSAGE)。dispose()。SuppressWarnings(unused)LogonFrame logon =new LogonFrame()。else/提示失败信息JOptionPane.showMessageDialog(null,此注册用户已存在!,注册失败!,JOptionPane.INFORMATION_MESSAGE)。txtUserName.setFocusable(true)。 catch (FileNotFoundException e) /
8、TODO Auto-generated catch blocke.printStackTrace()。 登录界面找回密码功能介绍:用户忘记密码,可以通过验证用户名和身份证号找回密码界面展示:图4-3 系统找回密码核心代码:public void userfindPwd()String username =txtUserName.getText().trim()。String id=txtId.getText().trim()。/用户名不能为空if(username.isEmpty()/提示信息JOptionPane.showMessageDialog(null,用户名不能为空!,用户注册,JO
9、ptionPane.INFORMATION_MESSAGE)。return 。/用户名为518if(username.length()18)/提示信息JOptionPane.showMessageDialog(null,用户名长度应在518之间!,用户注册,JOptionPane.INFORMATION_MESSAGE)。return 。/身份证号不能为空/身份证号不是18位时/验证身份证号User user =new User()。user.setUsername(username)。user.setId(id)。try User userr=user.userFindPwd()。if(us
10、err=null)JOptionPane.showMessageDialog(null,用户名或身份证号有误!,找回密码失败,JOptionPane.INFORMATION_MESSAGE)。elseJOptionPane.showMessageDialog(null,用户名:+userr.getUsername()+rn密码:+new String(userr.getPassword().trim(),找回密码成功,JOptionPane.INFORMATION_MESSAGE)。 catch (FileNotFoundException e) / TODO Auto-generated c
11、atch blocke.printStackTrace()。2、系统主界面功能介绍:包含系统管理、文件管理、操作管理、其他4个功能模块,具体模块功能后面详细介绍主界面展示:图4-4 系统主操作界面核心代码: /显示关于对话框 JMenuItem mntmAbout = new JMenuItem(u7CFBu7EDFu5173u4E8E)。 mnOther.add(mntmAbout)。 JMenuItem mntmHelp = new JMenuItem(u5E2Eu52A9)。 mntmHelp.addActionListener(new ActionListener() public v
12、oid actionPerformed(ActionEvent e) if(!helpFlag)panelHelp.setVisible(true)。String str=系统名称:rn。txtHelpInfor.setText(str)。helpFlag=true。elsepanelHelp.setVisible(false)。helpFlag=false。 )21.1、系统管理修改密码功能介绍:更改用户密码界面展示:图4-5 系统更改密码核心代码:public void updatepwd()String oldpassword=new String(txtOldPassword.getP
13、assword().trim()。String newpassword=new String(txtNewPassword.getPassword().trim()。String passwordok=new String(txtPasswordOk.getPassword().trim()。/旧密码不能为空if(oldpassword.isEmpty()/提示信息JOptionPane.showMessageDialog(null,旧密码不能为空!,用户更改密码,JOptionPane.INFORMATION_MESSAGE)。return 。/新密码不能为空/密码为615/确认密码不能为空
14、/两次密码不一致/是否更改密码成功try if(!user.userUpdatePwd(newpassword)/失败JOptionPane.showMessageDialog(null,原密码输入有误!,密码更改失败,JOptionPane.INFORMATION_MESSAGE)。else/成功JOptionPane.showMessageDialog(null,密码更改成功,密码更改成功,JOptionPane.INFORMATION_MESSAGE)。 catch (FileNotFoundException e) / TODO Auto-generated catch blocke.
15、printStackTrace()。21.2、系统管理注销账号功能介绍:退回到登陆界面界面:图4-6系统管理-注销账号核心代码:mntmLogoff.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) dispose()。LogonFrame frame = new LogonFrame()。 )。21.3、系统管理退出系统功能介绍:退出系统图4-7系统管理-退出系统核心代码: mntmExit.addActionListener(new ActionListener() pu
16、blic void actionPerformed(ActionEvent arg0) System.exit(0)。 )。22.1、文件管理导入文件功能介绍:导入类型是.TXT类型的通讯记录到通讯系统中界面展示:图4-8文件管理-导入文件核心代码:okButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) if(v=null)JOptionPane.showMessageDialog(null,导入失败,请选择文件进行导入,导入数据,JOptionPane.INFORMA
17、TION_MESSAGE)。return。elseUseFile.writeFile(fname, v)。JOptionPane.showMessageDialog(null,数据导入成功,导入数据,JOptionPane.INFORMATION_MESSAGE)。return。)。btnSelectFile.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) JFileChooser chooser = new JFileChooser()。FileNameExtensionFil
18、ter filter = new FileNameExtensionFilter(*.txt,txt)。chooser.setFileFilter(filter)。int returnVal = chooser.showOpenDialog(getParent()。String filename=null。if(returnVal = JFileChooser.APPROVE_OPTION) filename= chooser.getSelectedFile().toString()。txtFilePath.setText(filename)。/在文本框中显示文件路径if(!filename.
19、substring(filename.indexOf(.)+1,filename.length().equals(txt)JOptionPane.showMessageDialog(null,文件类型必需为*.xls|*.txt,文件选择失败,JOptionPane.INFORMATION_MESSAGE)。txtFilePath.setText()。return。)。22.1、文件管理导出文件功能介绍:将在同学通讯录系统中生成的文件以.TXT文件形式导出界面展示:图4-9文件管理-导出文件核心代码: mntmSava.addActionListener(new ActionListener(
20、) public void actionPerformed(ActionEvent e) JFileChooser chooser = new JFileChooser()。FileNameExtensionFilter filter = new FileNameExtensionFilter(*.txt,txt)。chooser.setFileFilter(filter)。chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES)。/选择目录和文件int returnVal = chooser.showSaveDialog
21、(getParent()。if(returnVal = JFileChooser.APPROVE_OPTION) String filename = chooser.getSelectedFile().toString()。/获取路径Vector cVector=new Vector()。 UseFile.readFile(fname, cVector)。if(filename.indexOf(.)=0)filename+=.txt。if(!filename.substring(filename.indexOf(.)+1,filename.length().equals(txt)JOption
22、Pane.showMessageDialog(null,文件类型必需为*.txt,导出,JOptionPane.INFORMATION_MESSAGE)。return。 UseFile.write(filename, cVector)。 )。23.1、操作管理增加通信记录功能介绍:增加新的同学信息,包括姓名、性别、电话、QQ号、邮箱、备注等界面展示:图4-10操作管理-添加通信记录核心代码:public void append()boolean flag=true。String name=txtName.getText()。boolean sex=Boolean.parseBoolean(rd
23、btnMale.isSelected()?true:false)。int age=this.sldAge.getValue()。String integrity=this.cobIntegrity.getSelectedItem().toString()。String tel=txtTel.getText()。String qq=txtQQ.getText()。String email=txtEmail.getText()。String memo=txtMemo.getText()。if(name.isEmpty()JOptionPane.showMessageDialog(null,姓名不能
24、为空!,增加通信信息,JOptionPane.INFORMATION_MESSAGE)。return。else/否,添加新行后,加入新数据。(javax.swing.table.DefaultTableModel) table.getModel().insertRow(countRows,new Object name,sex,age, integrity,tel,qq,email,memo )。row+。 table.repaint()。/刷新表格数据Classmate classmate=new Classmate(user.getUsername(),name,sex,age,integ
25、rity,tel,qq,email,memo)。cVector.add(classmate)。UseFile.writeFile(fname, cVector)。JOptionPane.showMessageDialog(null,添加成功!,增加通信信息,JOptionPane.INFORMATION_MESSAGE)。txtName.setText()。txtTel.setText()。txtQQ.setText()。23.2、操作管理删除通信记录功能介绍:通过姓名检索,找出要删除者的全部信息,选择删除或全部删除界面展示:图4-10操作管理-删除通信记录核心代码:/检索操作public v
26、oid Select()tryif(cVector.size()=0)JOptionPane.showMessageDialog(null,没有检索到任何记录!,删除通信信息,JOptionPane.INFORMATION_MESSAGE)。return。String name。name=txtName.getText()。if(name.isEmpty()tableLoadData()。/显示全部通信记录btnAllDel.setEnabled(true)。btnDelete.setEnabled(true)。DeleteFalg=true。elseSelectByName(name)。/姓
27、名检索出要删除的通信记录btnDelete.setEnabled(true)。DeleteFalg=false。catch(Exception e)23.3、操作管理更新通信记录功能介绍:通过姓名检索出要更新的全部信息,然后通过更新相应信息重新设置被检索出来人的信息界面展示:图4-11操作管理-更新通信记录核心代码:public void Update()boolean flag=true。String name=txtName.getText()。boolean sex=Boolean.parseBoolean(rbtnMale.isSelected()?true:false)。int ag
28、e=this.sldAge.getValue()。String integrity=this.cobIntegrity.getSelectedItem().toString()。String tel=txtTel.getText()。String qq=txtQQ.getText()。String email=txtEmail.getText()。String memo=txtMemo.getText()。if(name.isEmpty()JOptionPane.showMessageDialog(null,姓名不能为空!,更新信息,JOptionPane.INFORMATION_MESSAGE)。return。if(flag)cVector.remove(cm)。cm.setAge(age)。cm.setEmail(email)。cm.setQq(qq)。cm.setTel(tel)。cm.setSex(sex)。cm.setIntegrity(integrity)。cm.setMemo(memo)。cVector.add(cm)。UseFile.updateFile(fname, cVector)。JOpt