课程设计—通讯录管理系统
发布时间:2025-12-09 21:10:58
浏览次数:3
一、团队成员介绍
| 成员名字 | 负责模块 | 博客链接 |
| 陈文杰(组长) | 前期调查、功能设计,账号系统界面设计、账号(注册、储存、登录)等功能实现、代码规范 | |
| 卢怡康 | 通讯录系统界面设计、通讯录增删改查、文件储存等功能实现、博客编写 | |
二、项目介绍
用户可通过注册、登录来进入通信录管理系统。进入系统后可选择(更新信息、查找、增加、删除、修改、保存、退出)等功能进行通讯录信息的操作。
三、功能架构图
四、面向对象设计包图、类图
包图
类图
五、项目运行截图
1、初始界面
2、通讯录系统功能界面
3、登录界面
a)注册
b)登录失败时
4、更新信息
5、查找联系人
6、添加联系人
7、删除联系人
8、修改联系人
9、保存联系人
六、项目的关键代码
a)初始化账号类,读入文件内容
/*** 初始化账号类,读入文件内容*/public AccountNumber() {itemList = new ArrayList<>();File file = new File("D:\\addressystem\\account.txt");BufferedReader reader = null;try {reader = new BufferedReader(new FileReader(file));String tempString = null;while ((tempString = reader.readLine()) != null) {String[] arr = tempString.split("\\s+");User user = new User(arr[0], arr[1]);itemList.add(user);}reader.close();} catch (IOException e) {e.printStackTrace();} finally {if (reader != null) {try {reader.close();} catch (IOException e1) {}}}}
b)账号登录。返回对应账号的通讯录地址
/*** 账号登录。返回对应账号的通讯录地址**/public String signIn1(String name, String password) {for (int i = 0; i < itemList.size(); i++) {if (itemList.get(i).getName().equals(name) && itemList.get(i).getPassword().equals(password)) {String str = "D:\\addressystem\\" + itemList.get(i).getId() + ".txt";return str;}}return null;}/*注册用户信息,覆写文件*/public void post(User user) throws IOException {//写入新注册的用户信息File f = new File("D:\\addressystem\\account.txt");if (f.exists()) {System.out.print("文件存在");} else {System.out.print("文件不存在");try {f.createNewFile();} catch (IOException e) {e.printStackTrace();}}BufferedWriter output = null;try {output = new BufferedWriter(new FileWriter(f, true));} catch (IOException e) {e.printStackTrace();}output.write("\n");//换行output.write(user.getName() + " " + user.getPassword());output.flush();output.close();//创建文件String path = "D:\\addressystem\\" + user.getId() + ".txt";System.out.println(user.getId());File file = new File(path);file.createNewFile();//给新通讯录添加默认联系人String str = "D:\\addressystem\\" + user.getId() + ".txt";File x = new File(str);if (x.exists()) {System.out.print("文件存在");} else {System.out.print("文件不存在");try {x.createNewFile();} catch (IOException e) {e.printStackTrace();}}BufferedWriter output1 = null;try {output1 = new BufferedWriter(new FileWriter(x, true));} catch (IOException e) {e.printStackTrace();}output1.write("C 陈文杰 123456789 南平");output1.flush();output1.close();//将user加入到itemList中itemList.add(user);}}
c)通讯录增删改查功能
//构造函数,读取地址为str的文件内容public MailList(String str) {nameList = new ArrayList<>();File file = new File(str);BufferedReader reader = null;try {reader = new BufferedReader(new FileReader(file));String tempString = null;while ((tempString = reader.readLine()) != null) {String[] arr = tempString.split("\\s+");Contacts con = new Contacts(arr[1], arr[2], arr[3], arr[0]);nameList.add(con);}reader.close();} catch (IOException e) {e.printStackTrace();} finally {if (reader != null) {try {reader.close();} catch (IOException e1) {}}}}//根据名字查找联系人public Contacts foundName(String name) {for (int i = 0; i < nameList.size(); i++) {if (nameList.get(i).getName().equals(name)) {return nameList.get(i);}}return null;}//添加联系人public int add(Contacts co) {int tep = 0;for (int i = 0; i < nameList.size(); i++) {if (nameList.get(i).equals(co)) {tep = 1;}}if (tep == 1) {return 0;} else {nameList.add(co);return 1;}}//删除联系人public int delete(String name) {int tep = 0;for (int i = 0; i < nameList.size(); i++) {if (nameList.get(i).getName().equals(name)) {tep = 1;nameList.remove(i);}}if (tep == 0) {return 0;} else {return 1;}}//修改联系人public int change(String name, Contacts co) {int tep = 0;for (int i = 0; i < nameList.size(); i++) {if (nameList.get(i).getName().equals(name)) {tep = 1;Collections.replaceAll(nameList, nameList.get(i), co);}}if (tep == 0) {return 0;} else {return 1;}}//保存通讯录信息public void preservation(String str) {String mail = new String();for (int i = 0; i < nameList.size(); i++) {mail += nameList.get(i).getInitials() + " " + nameList.get(i).getName() + " " + nameList.get(i).getNumber() + " " + nameList.get(i).getAddress() + "\n";}PrintStream stream = null;try {stream = new PrintStream(str);//写入的文件strstream.print(mail);//写入的字符串} catch (FileNotFoundException e) {e.printStackTrace();}stream.close();}}
d)更新信息
private void toUpdateButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here://更新信息Collections.sort(mail.getNameList()); // 升序排列DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();dtm.setRowCount(0);for (int i = 0; i < mail.getNameList().size(); i++) {Vector vadd = new Vector();//构造一个空向量VAddvadd.add(mail.getNameList().get(i).getInitials());vadd.add(mail.getNameList().get(i).getName());vadd.add(mail.getNameList().get(i).getNumber());vadd.add(mail.getNameList().get(i).getAddress());dtm.addRow(vadd);//添加完信息后表格自动添加一行。}}
七、代码静态扫描
八、总结
通过这个程序设计,我们不仅提高了动手操作能力,对Java以及GUI有了更深的认识, 能够更好地运用Java进行编程设计,同时在思维、看待问题的全面性等方面也有了很大的提高。不过由于时间、经验不够、对语言的掌握程度不深等问题,在这个系统设计还存在一些问题,比如内存设计还不够完善,整个系统的流畅性等,希望可以在今后的设计上能够解决这些问题,做的更好。此外,对程序的测试应该要仔细,根据模块的特点和测试阶段,采用各种软件测试方法对程序进行测试,确保各个模块的正确性和完整性,最后集成起来测试其是否正确和完整地实现了问题描述中要求的功能。