java编写这个通讯录管理系统_Java如何实现通讯录管理系统
Java如何实现通讯录管理系统
发布时间:2020-07-28 09:39:42
来源:亿速云
阅读:65
作者:Leah
这篇文章将为大家详细讲解有关Java如何实现通讯录管理系统,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
本文实例为大家分享了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如何实现通讯录管理系统相关推荐
- java宠物商店管理系统_Java实现宠物商店管理系统
Java实现宠物商店管理系统,宠物,宠物商店,数组,您的,还需要 Java实现宠物商店管理系统 易采站长站,站长之家为您整理了Java实现宠物商店管理系统的相关内容. 本文实例为大家分享了Java实现 ...
- 用java编写战舰 游戏吗_java – 战舰游戏 – 船舶重叠
我正在使用ACM库在 Java中编写一个简单的战舰游戏. 游戏开始后,应该将船只放在画布上的随机位置,但问题是船只可能会互相覆盖,这在游戏中是不允许的.如何避免将船放在彼此之上? 我的代码是: pri ...
- java开发企业级权限管理系统_Java开发企业级权限管理系统 视频教程
第1章 课程整体概述与权限管理系统介绍 1-1 为什么企业级项目需要权限管理 1-2 权限管理的核心是什么? 1-3 理想中的权限管理应该是什么样的? 1-4 主流开源权限管理框架有哪些? 1-5 1 ...
- java中交通灯管理系统_java案例--交通灯管理系统学习
一.需求分析 刚接到一个项目或者面试题(总之是一个相对比较复杂的问题时),应该对认真阅读问题的 要求和描述,并通过对这些的分析进行抽象,通过一个个对象的方式来考虑自己的程序该 怎么写.所以,首先来看看 ...
- java中的JDBC用户管理系统_Java+JDBC学生信息管理系统
base包下: package base; import java.sql.ResultSet; import java.sql.SQLException; import dao.AdminDAO; ...
- java编写教师类输出_Java类和对象的区别和联系,超简单易懂!
在面向对象的编程语言中,类和对象必然是最核心的特性之一.本文主要介绍Java中的类和对象. 示例 以班级成员为例,班上有小红.小明.小李,还有王老师.张老师和魏老师,我们认为他们都属于"人类 ...
- java编写系统登录界面_java 登陆界面怎么写,连接数据库后
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 界面是 package 界面类; import javax.jws.soap.SOAPBinding.Use; import javax.swing.JB ...
- java书店库存系统论文_JAVA论文网上书店管理系统优秀毕业论文
JAVA论文网上书店管理系统优秀毕业论文 沈阳航空工业学院毕业设计(论文)I网上书店系统院 系专 业班 级学 号姓 名指导教师负责教师沈阳航空工业学院毕业设计(论文)II摘 要20 世纪末,随着计算机 ...
- java图书馆借还书系统_java图书馆借阅归还管理系统OA源码下载
java图书馆借阅归还管理系统OA源码下载 JAVA+MYSQL 系统介绍 图书馆管理系统主要的目的是实现图书馆的信息化管理.图书馆的主要业务就是新书的借阅和归还,因此系统最核心的功能便是实现图书的借 ...
- 基于java的流量数据检测_java网站流量统计管理系统
每天记录学习,每天会有好心情.*^_^* 今天将为大家分析一个基于web的java网站流量统计管理系统,基于Web的网站访问流量统计系统在功能上强化了对用户行为的统计和分析,有利于网站管理者.开发者根 ...
最新文章
- php 递归实现无限极分类和排序_Laravel框架实现无限极分类
- 普大喜奔 | Azure 免费送网站SSL证书啦!
- GitLab结合Eclipse的简单使用 - 20190211
- JDK源码学习路线~每天学一点~每天进步一点点
- 求最大公约数c语言代码_辗转相除求最大公约数原理
- vue 子页面调用父页面常用方式
- C++ 实现把非静态成员函数作为回调函数(非static)
- 智力题 - 士兵编队与传讯员
- python 判断是字母的多种方法
- 组件中使用_Cocos Creator中Button组件使用详解
- Python 身份证校验代码
- 底层网工、0基础、记性差,学习CCIE/HCIE,到底是啥体验?
- layui上传文件请求接口异常_解决layui table表单提示数据接口请求异常的问题
- KeyError: ‘Worksheet sheet does not exist.‘
- OSPF你懂多少之经典问题50个
- 关于物联网,互联网我们用到的通信
- 如何从0到1组建敏捷团队?
- A. Sequence with Digits
- 医疗电子方案——血压计方案
- linux安装appt服务,Centos下pptd ***搭建
热门文章
- 【基础巩固】文件流读写、大文件移动 FileStream StreamWriter File Path Directory/ ,m资料管理器(递归)...
- 单片机考试不挂科就等于学好单片机了吗,别太天真了
- Quartz集群配置报错 This scheduler instance (XXXX) is still active but was recovered by another instance...
- 替代YY语音,自行搭建语音实时服务器
- 图片放大后不清楚怎么办?
- ORA-20001: Invalid or inconsistent input values
- isbn号码 (java实现)
- 创灵原始与鸿蒙,上古启示录
- JS实现图片不存在时显示默认图片
- notes java api_Java中通过Notes API访问Domino数据库