下面是源代码:
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 ArrayListlist = 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 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 推荐教程:《Java教程》
以上就是Java 实现通讯录管理系统教程的详细内容,更多请关注其它相关文章!