Android通讯录管理(获取联系人、通话记录、短信消息)
>
java编写这个通讯录管理系统
java编写这个通讯录管理系统_Java如何实现通讯录管理系统
咕噜噜在芬兰
原创
关注
3点赞·2305人阅读
Java如何实现通讯录管理系统
发布时间:2020-07-28 09:39:42
来源:亿速云
阅读:65
作者:Leah
这篇文章将为大家详细讲解有关Java如何实现通讯录管理系统,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
本文实例为大家分享了java实现通讯录管理系统的具体代码,供大家参考,具体内容如下
完成项目的流程:
1根据需求,确定大体方向
2功能模块分析
3界面实现
4功能模块设计
5coding
6代码测试
下面是源代码:import javaawtContainer;
import javaawtGridLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaioBufferedReader;
import javaioFileNotFoundException;
import javaioFileReader;
import javaioFileWriter;
import javaioIOException;
import javautilArrayList;
import javautilScanner;
import javautilconcurrentSynchronousQueue;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJPanel;
import javaxswingWindowConstants;
import javaxswingtexthtmlHTMLDocumentIterator;
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 = listsize();
//构造函数
public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){
thisid = id;
thisname = name;
thissex = sex;
thisaddress = address;
thise_mail = e_mail;
thisphoneNumber = phoneNumber;
}
public String toString(){
return "编号:"+id+" 姓名:"+name+" 性别:"+sex+" 通讯地址:"+address+" 邮箱地址:"+e_mail+" 电话:"+phoneNumber;
}
/
添加功能
/
public static void addFunction(){//添加功能
Infro infro = new Infro("","","","","","");
Systemoutprintln("请输入添加的数据:");
Scanner in = new Scanner(Systemin);
Systemoutprintln("输入编号:");
infroid = innext();
Systemoutprintln("输入姓名:");
infroname = innext();
Systemoutprintln("输入性别:");
infrosex = innext();
Systemoutprintln("输入通讯地址:");
infroaddress = innext();
System
outprintln("输入邮箱地址:");
infroe_mail = innext();
Systemoutprintln("输入电话:");
infrophoneNumber = innext();
listadd(index,infro);
index++;
if(listisEmpty()){
Systemoutprintln("数据添加失败啦");
}else{
Systemoutprintln("数据添加成功啦");
len++;//list集合长度加一
// Systemoutprintln(listget(0)toString());
}
}
// public static void deleteFunction(){//删除功能
// Systemoutprintln("输入要删除的联系人的编号");
// Scanner in_2 = new Scanner(Systemin);
// String d1 = in_2nextLine();
// for(int a= 0; a
// if(d1equals(listget(a)id)){
// listremove(listget(a));
// len --;
// }
// }
// }
/
删除功能
/
public static void deleteFunction(){
Systemoutprintln("输入要删除的联系人的编号");
Scanner in_2 = new Scanner(Systemin);
String d1 = in_2nextLine();
javautilIterator it = listiterator();
while (ithasNext()){
Infro infro = itnext();
if (infroidequals(d1)){
itremove();
--index;//一定要加这个,否则当做了删除 *** 作再做添加 *** 作的时候会出现异常(类似于指针,栈)
Systemoutprintln("删除完毕"+"此时通讯录记录条数为:" + --len);
}
}
}
/
修改功能
/
public static void reditFunction(){
Systemoutprintln("输入要修改的通讯录的Id");
Scanner in_r = new Scanner(Systemin);
String r1 = in_rnextLine();
for(int a = 0; a < len;a++){
if(r1equals(listget(a)id)){
Systemoutprintln("输入修改后的姓名:");
String name_1 = in_rnext();
listget(a)name = name_1;
Systemoutprintln("输入修改后的性别:");
String sex_1 = in_rnext();
listget(a)sex = sex_1;
Systemoutprintln("输入修改后的通讯地址:");
String address_1 = in_rnext();
listget(a)address = address_1;
Systemoutprintln("输入修改后的邮箱地址:");
String e_mail_1 = in_rnext();
listget(a)e_mail = e_mail_1;
Systemoutprintln("输入修改后的电话:");
String phoneNumber_1 = in_rnext();
listget(a)phoneNumber = phoneNumber_1;
Systemoutprintln("数据修改完毕");
}
}
}
/
查询功能
/
public static void searchFunction() throws Exception{//查询功能
Systemoutprintln("请输入要查询的姓名:");
Scanner in_1 = new Scanner(Systemin);
String s1=in_1nextLine();
for(int a= 0; a
if(s1equals(listget(a)name)){
Systemoutprintln(listget(a)toString());
}
}
}
/
显示功能
/
public static void showFunction(){
for(int i = 0 ;i
Systemoutprintln(listget(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]=listget(i)toString();
writerwrite(strwriter[i]);
writerwrite("\r\n");
Systemoutprintln("成功写入一行数据到 通讯录管理txt 中");
}
writerclose();//关闭写入流,释放资源
}
/
读取功能
/
public static void readFunction() throws IOException{
FileReader reader = new FileReader("通讯录管理txt");
BufferedReader br = new BufferedReader(reader);
String str;
while((str = brreadLine()) != null){//每次读取一行文本,判断是否到达文件尾
Systemoutprintln(str);
}
brclose();
}
}
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("读取本地联系人");
jpsetLayout(new GridLayout(2,4,5,5));//新建网格布局管理器(行数,列数,组件间的水平垂直间距)
jpadd(button1);
jpadd(button2);
jpadd(button3);
jpadd(button4);
jpadd(button5);
jpadd(button6);
jpadd(button7);
cadd(jp);//将JPanel面板jp添加到顶级容器c中
setSize(600,500);
setTitle("通 讯 录 管 理 系 统");
setVisible(true);
setResizable(false);//窗体大小由程序员决定,用户不能自由改变大小
setDefaultCloseOperation(WindowConstantsEXIT_ON_CLOSE);
/
按键响应
/
button1addActionListener(new ActionListener(){//添加功能实现
public void actionPerformed(ActionEvent arg0){
InfroaddFunction();
}
});
button2addActionListener(new ActionListener(){//删除功能实现
public void actionPerformed(ActionEvent arg0){
InfrodeleteFunction();
}
});
button3addActionListener(new ActionListener(){//修改功能实现
public void actionPerformed(ActionEvent arg0){
InfroreditFunction();
}
});
button4addActionListener(new ActionListener(){//查询功能实现
public void actionPerformed(ActionEvent arg0){
try {
InfrosearchFunction();
} catch (Exception e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
});
button5addActionListener(new ActionListener(){//显示功能实现
public void actionPerformed(ActionEvent arg0){
InfroshowFunction();
}
});
button6addActionListener(new ActionListener(){//保存功能实现
public void actionPerformed(ActionEvent arg0){
try {
InfrowriteFunction();
} catch (IOException e) {
eprintStackTrace();
}
}
});
button7addActionListener(new ActionListener(){//读取功能实现
public void actionPerformed(ActionEvent arg0){
try {
InfroreadFunction();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Demo();
Infro a = new Infro("", "", "", "", "", "");
}
}
关于Java如何实现通讯录管理系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
第一种:CotactsUI
首先导入头文件
通过代理方法获取通讯录中联系人信息
//这是运行图
Contacts使用步骤:
现在运行一下
结果直接崩了,报错结果要在infoplist中配置一个NSContactsUsageDescription 的key
再运行一下
点击控制器view后
再对比虚拟机的通讯录
两种方法都介绍了哦
以上就是关于跪求大神给份用Android做的手机通讯录的完整源码,能够打电话,发短信,创建等等,谢谢了。全部的内容,包括:跪求大神给份用Android做的手机通讯录的完整源码,能够打电话,发短信,创建等等,谢谢了。、android开发怎样获取通讯录联系人信息、java通讯录管理系统设计代码怎么编译等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)