本文实例为大家分享了java实现通讯录管理系统的具体代码,供大家参考,具体内容如下

完成项目的流程:

1.根据需求,确定大体方向

2.功能模块分析

3.界面实现

4.功能模块设计

5.coding

6.代码测试

下面是源代码:import java.awt.Container;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Scanner;

import java.util.concurrent.SynchronousQueue;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.WindowConstants;

import javax.swing.text.html.HTMLDocument.Iterator;

class Infro{

public String id;

public String name;

public String sex;

public String address;

public String e_mail;

public String phoneNumber;

static int index = 0;

static ArrayList list = new ArrayList();

static int len = list.size();

//构造函数

public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){

this.id = id;

this.name = name;

this.sex = sex;

this.address = address;

this.e_mail = e_mail;

this.phoneNumber = phoneNumber;

}

public String toString(){

return "编号:"+id+" 姓名:"+name+" 性别:"+sex+" 通讯地址:"+address+" 邮箱地址:"+e_mail+" 电话:"+phoneNumber;

}

/**

* 添加功能

**/

public static void addFunction(){//添加功能

Infro infro = new Infro("","","","","","");

System.out.println("请输入添加的数据:");

Scanner in = new Scanner(System.in);

System.out.println("输入编号:");

infro.id = in.next();

System.out.println("输入姓名:");

infro.name = in.next();

System.out.println("输入性别:");

infro.sex = in.next();

System.out.println("输入通讯地址:");

infro.address = in.next();

System.

out.println("输入邮箱地址:");

infro.e_mail = in.next();

System.out.println("输入电话:");

infro.phoneNumber = in.next();

list.add(index,infro);

index++;

if(list.isEmpty()){

System.out.println("数据添加失败啦");

}else{

System.out.println("数据添加成功啦");

len++;//list集合长度加一

// System.out.println(list.get(0).toString());

}

}

// public static void deleteFunction(){//删除功能

// System.out.println("输入要删除的联系人的编号");

// Scanner in_2 = new Scanner(System.in);

// String d1 = in_2.nextLine();

// for(int a= 0; a

// if(d1.equals(list.get(a).id)){

// list.remove(list.get(a));

// len --;

// }

// }

// }

/**

* 删除功能

**/

public static void deleteFunction(){

System.out.println("输入要删除的联系人的编号");

Scanner in_2 = new Scanner(System.in);

String d1 = in_2.nextLine();

java.util.Iterator it = list.iterator();

while (it.hasNext()){

Infro infro = it.next();

if (infro.id.equals(d1)){

it.remove();

--index;//一定要加这个,否则当做了删除操作再做添加操作的时候会出现异常(类似于指针,栈)

System.out.println("删除完毕"+"此时通讯录记录条数为:" + --len);

}

}

}

/**

* 修改功能

**/

public static void reditFunction(){

System.out.println("输入要修改的通讯录的Id");

Scanner in_r = new Scanner(System.in);

String r1 = in_r.nextLine();

for(int a = 0; a < len;a++){

if(r1.equals(list.get(a).id)){

System.out.println("输入修改后的姓名:");

String name_1 = in_r.next();

list.get(a).name = name_1;

System.out.println("输入修改后的性别:");

String sex_1 = in_r.next();

list.get(a).sex = sex_1;

System.out.println("输入修改后的通讯地址:");

String address_1 = in_r.next();

list.get(a).address = address_1;

System.out.println("输入修改后的邮箱地址:");

String e_mail_1 = in_r.next();

list.get(a).e_mail = e_mail_1;

System.out.println("输入修改后的电话:");

String phoneNumber_1 = in_r.next();

list.get(a).phoneNumber = phoneNumber_1;

System.out.println("数据修改完毕");

}

}

}

/**

* 查询功能

**/

public static void searchFunction() throws Exception{//查询功能

System.out.println("请输入要查询的姓名:");

Scanner in_1 = new Scanner(System.in);

String s1=in_1.nextLine();

for(int a= 0; a

if(s1.equals(list.get(a).name)){

System.out.println(list.get(a).toString());

}

}

}

/**

* 显示功能

**/

public static void showFunction(){

for(int i = 0 ;i

System.out.println(list.get(i).toString());

}

}

/**

* 保存功能

**/

public static void writeFunction() throws IOException{

FileWriter writer = new FileWriter("通讯录管理.txt");

for(int i = 0 ;i

String []strwriter = new String[len];

strwriter[i]=list.get(i).toString();

writer.write(strwriter[i]);

writer.write("\r\n");

System.out.println("成功写入一行数据到 通讯录管理.txt 中");

}

writer.close();//关闭写入流,释放资源

}

/**

* 读取功能

**/

public static void readFunction() throws IOException{

FileReader reader = new FileReader("通讯录管理.txt");

BufferedReader br = new BufferedReader(reader);

String str;

while((str = br.readLine()) != null){//每次读取一行文本,判断是否到达文件尾

System.out.println(str);

}

br.close();

}

}

public class Demo extends JFrame {

/**

* 界面设计

**/

public Demo(){

Container c = getContentPane(); //定义一个顶级容器c

JPanel jp = new JPanel(); //新建JPanel面板--jp

JButton button1 = new JButton("新建联系人");

JButton button2 = new JButton("删除联系人");

JButton button3 = new JButton("编辑联系人");

JButton button4 = new JButton("查找联系人");

JButton button5 = new JButton("显示所有联系人");

JButton button6 = new JButton("保存联系人到本地");

JButton button7 = new JButton("读取本地联系人");

jp.setLayout(new GridLayout(2,4,5,5));//新建网格布局管理器(行数,列数,组件间的水平垂直间距)

jp.add(button1);

jp.add(button2);

jp.add(button3);

jp.add(button4);

jp.add(button5);

jp.add(button6);

jp.add(button7);

c.add(jp);//将JPanel面板jp添加到顶级容器c中

setSize(600,500);

setTitle("*通 讯 录 管 理 系 统*");

setVisible(true);

setResizable(false);//窗体大小由程序员决定,用户不能自由改变大小

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

/**

*按键响应

*

**/

button1.addActionListener(new ActionListener(){//添加功能实现

public void actionPerformed(ActionEvent arg0){

Infro.addFunction();

}

});

button2.addActionListener(new ActionListener(){//删除功能实现

public void actionPerformed(ActionEvent arg0){

Infro.deleteFunction();

}

});

button3.addActionListener(new ActionListener(){//修改功能实现

public void actionPerformed(ActionEvent arg0){

Infro.reditFunction();

}

});

button4.addActionListener(new ActionListener(){//查询功能实现

public void actionPerformed(ActionEvent arg0){

try {

Infro.searchFunction();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

button5.addActionListener(new ActionListener(){//显示功能实现

public void actionPerformed(ActionEvent arg0){

Infro.showFunction();

}

});

button6.addActionListener(new ActionListener(){//保存功能实现

public void actionPerformed(ActionEvent arg0){

try {

Infro.writeFunction();

} catch (IOException e) {

e.printStackTrace();

}

}

});

button7.addActionListener(new ActionListener(){//读取功能实现

public void actionPerformed(ActionEvent arg0){

try {

Infro.readFunction();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

}

public static void main(String[] args) {

// TODO Auto-generated method stub

new Demo();

Infro a = new Infro("", "", "", "", "", "");

}

}

推荐教程:《Java教程》

java编写通信录管理系统_Java 实现通讯录管理系统教程相关推荐

  1. java通信录教程_java实现通讯录管理系统

    本文实例为大家分享了java实现通讯录管理系统的具体代码,供大家参考,具体内容如下 完成项目的流程: 1.根据需求,确定大体方向 2.功能模块分析 3.界面实现 4.功能模块设计 5.coding 6 ...

  2. java销售管理系统实验报告_java学生通讯录管理系统实验报告

    java学生通讯录管理系统实验报告 (4页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 19.90 积分 宁波大红鹰学院 课课程程设设计计课程设计名称: ...

  3. 微课--Python使用tkinter和SQLite编写通信录管理程序(21分钟)

    全国高校教师Python课程高级研修班(线上,11月20-21日) 中国大学MOOC"Python程序设计基础"第5次开课 推荐教材:Python程序设计入门与实践 I  S  B ...

  4. Java影院网上购票管理系统_java影院售票管理系统

    一个完善的电影院售票管理系统,可以帮助电影院工作人员提升工作效率, 辅助电影院工... 电影院售票管理系统UML_计算机软件及应用_IT/计算机_专业资料.业务需求 1... Jsp 影院售票系统的架 ...

  5. 北大青鸟java超市账单管理系统_java超市账单管理系统.pdf

    java超市账单管理系统 Java 北大青鸟 (天津)第二单元超市账单管理系统 项目整体: 项目dao 包: 项目entity 包: 项目filter 包: 项目servlet 包: 项目test 包 ...

  6. php企业网站通讯录管理系统,EML企业通讯录管理系统v5.4.15 经典版+手机端实时查看人员联系方式+客户关系管理系统...

    企业通讯录管理系统,向企业员工随时随地的提供企业通讯录信息,用户可在手机端实时查看人员联系方式,拨打电话等全面提高了企业内部沟通效率. 主要功能有:用户管理(添加用户,删除用户用户,更新用户资料):通 ...

  7. java自定义封装一个方法_Java自定义套件封装教程

    Java自定义套件封装教程 时间:2017-07-28     来源:华清远见JAVA学院 各位亲爱的小伙伴们大家好,近很多伙伴都问我该怎么做Java自定义套件封装,今天华清Java学院小编在这里做了 ...

  8. java编写学生管理系统_Java实现学生管理系统

    导读热词 项目描述:通过管理员帐号登录,对学员信息进行管理.可以实现学员信息的增加.修改.删除.查询. 知识点:数组.do{}while循环.for循环.if语句.switch条件语句 学生管理系统的 ...

  9. java 个人通讯录_java个人通讯录管理系统

    展开全部 import java.util.Arrays; public class AddressBook { private int totalContacts; // 现在通讯录中的总数 pri ...

最新文章

  1. 通过了OCP的全部考试后的感受(ZT)
  2. Spark Catalyst
  3. 职业标准体系一般有几个层次划分_全国首个粤菜标准体系规划发布
  4. linux内核亲和性,Linux中CPU亲和性(go)
  5. 同一工作组无法访问_工作组,域
  6. PHP函数调用及循环体内定义大型变量效率的研究
  7. mysql 5.6 json查询_mysql5.6及以下版本如何查询数据库里的json
  8. java中contains的用法_好程序员Java教程分享Java中this的几种用法
  9. C语言打印九九乘法表
  10. 产品读书《一页纸项目管理》
  11. 2016国内移动广告平台排行榜
  12. Amaze UI后台管理模板 v2.7.2
  13. 划线法构造三角形单元插值函数
  14. onkeyup事件只能输入数字,字母,下划线等
  15. 第十四周学习周报20181210-20181216
  16. 数据压缩作业1-1|利用Audacity分析浊音、清音、爆破音的时域及频域特性
  17. python爬取豆瓣书籍_Python 爬取豆瓣读书标签下的书籍
  18. c语言变量名拼音,C语言的32个关键字(读音、用法、注释)转来的,给刚接触C的...
  19. web页面内调取QQ应用
  20. linux to go把linux系统装进U盘里随插随用

热门文章

  1. unzip 报错error [clas.zip]:  missing 1844 bytes in zipfile
  2. IDEA中 @override报错的解决方法
  3. ionic html5 上传图片,ionic4+angular7+cordova上传图片功能的实例代码
  4. 处于停机等非正常状态_一文聊透 Dubbo 优雅停机
  5. [转载] 【基础教程】Python input()函数:获取用户输入的字符串
  6. Java ObjectInputStream enableResolveObject()方法与示例
  7. flask mysql 版本_flask 数据库字段类型
  8. 关于二手交易用户指南怎么写_让用户拍案叫绝文案怎么写?试试这3个方法
  9. c语言位运算+乘法,关于c语言中的位运算。。。
  10. 数据分析 数据科学_数据科学中的数据分析