资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java代码编译教程 java代码的编译执行流程

java通讯录管理系统设计代码怎么编译

java编写这个通讯录管理系统

10年积累的网站设计、做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先建设网站后付款的网站建设流程,更有黄石港免费网站建设让你可以放心的选择与我们合作。

java编写这个通讯录管理系统_Java如何实现通讯录管理系统

咕噜噜在芬兰

原创

关注

3点赞·2305人阅读

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程序代码?

在DOS 窗口下。进入你写的程序目录。例如你把写的程序保存到D:\\a.java\x0d\x0a\x0d\x0a这个时候在DOS下进入D:\\\x0d\x0a\x0d\x0a然后调用JDK的编译器javac程序\x0d\x0a\x0d\x0aD:\\javac a.java\x0d\x0a\x0d\x0a如果成功,在同一目录下会产生一个扩展名为.class的字节码,然后调用JDK的java程序是用来启动虚拟机\x0d\x0a\x0d\x0aD:\\java a\x0d\x0a\x0d\x0a如果,没有编写上的错误,就可以看到运行结果了。

如何编译java

用命令提示符编译java程序的步骤:

1.先新建文本文档,输入自己的java程序。

这里我写一个简单的java程序,来做示范。

import java.util.*;

public class HelloDate{

public static void main(String[] args)

{

System.out.println("Hello,it's:");

System.out.println(new Date());

}

}

2.然后另存为一个java文件。

1.选择文件---另存为---名称为“HelloDate.java”-----选择“所有文件”。

2.记住自己这个文件的存储位置。(方便调用!)

3.打开程序----附件---命令提示符。

4.由于我的那个java文本保存在了F:/java/(在F盘下的java文件夹里)下,所以如果要想编译,就需要先通过命令提示符进入java这个文件夹,具体步骤如下:

1.进入F盘:输入【F:】,然后按下回车键【Enter】

2.输入【cd java】,按下回车键【Enter】

这样就已经进入了。这里的cd的意思就是进入的意思。

5.紧接着调用java编译器进行编译。

输入【javac HelloDate。java】,然后按下回车键【Enter】

然后运行结果。

输入【java HelloDate】,按下回车键【Enter】

经验总结:运行一个java程序的大概的流程是:

书写源代码------编译-------运行----结束。

注意事项:

1.在输入的时候一定要注意区分大小写。

2.操作之前要保证自己的电脑配置了java的运行环境。

如何在CMD编译和运行JAVA代码?

cd到你java文件存放的目录,比如你的java文件的名称为HelloWorld.java,在cmd中输入javac HelloWorld.java 敲击回车.

这个命令会将你的java文件编译成class文件,然后在cmd框中输入java HelloWorld敲击回车就能运行你的java文件输出结果.

java优点:

java是纯面向对象编程的语言;

平台无关性 (一次编译,到处运行;Write Once,Run Anywhere);

java提供了许多内置的类库,通过这些类库,简化了开发人员的设计工作,同时缩短了项目开发时间;

提供了对Web应用开发的支持,例如,Applet,Servlet,和JSP可以用来开发Web应用程序,,Socket,RMI可以用来开发分布式应用程序的类库。


网页题目:java代码编译教程 java代码的编译执行流程
网页网址:http://cdkjz.cn/article/doghidh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220