网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java编写通讯录的代码,个人通讯录java代码

用Java编辑通讯录

附件:源程序清单 import java.awt.*; import java.awt.event.*; class Info { public static String name,address,mail,telephone; Info(){} } public class addressBook extends Frame implements ActionListener { private MenuItem noteAdd=new MenuItem("Add"); private MenuItem noteDel=new MenuItem("Del"); private MenuItem noteEdit=new MenuItem("Modify"); private MenuItem noteExit=new MenuItem("Exit"); private List noteList=new List(); private String[][] message=new String [1000][4]; public Info notes=new Info(); public addressBook(){ super("通讯录 向阳"); Menu note=new Menu("Edit"); note.add(noteAdd); note.add(noteDel); note.add(noteEdit); note.addSeparator(); note.add(noteExit); MenuBar bar=new MenuBar(); bar.add(note); setMenuBar(bar); add(noteList); noteAdd.addActionListener(this); noteDel.addActionListener(this); noteEdit.addActionListener(this); noteExit.addActionListener(this); noteList.addActionListener(this); addWindowListener(new WindowCloser()); setSize(300,400); show(); } public void actionPerformed(ActionEvent e){ if(e.getSource()==noteAdd){ notes.mail=null; notes.name=null; notes.address=null; notes.telephone=null; int index=noteList.getItemCount(); EditDialog dlg=new EditDialog(this,"添加通讯录"); if(dlg.isOk){ message[index][0]=dlg.textName.getText(); message[index][1]=dlg.textAddress.getText(); message[index][2]=dlg.textEmail.getText(); message[index][3]=dlg.textTelephone.getText(); if (message[index][0]!=null){ String s="姓名:"+message[index][0]+";\t地址"+message[index][1]+";\tE-mail"+message[index][2]+";\t电话"+message[index][3]; noteList.add(s); } } dlg.dispose(); }else if(e.getSource()==noteDel){ ConfirmDialog dlg=new ConfirmDialog(this,"确认删除","确定要删除这一条吗?"); if (dlg.close){ noteList.remove(noteList.getSelectedIndex()); } dlg.dispose(); }else if(e.getSource()==noteEdit||e.getSource()==noteList){ int i=noteList.getSelectedIndex(); if(i!=-1){ notes.name=message[i][0]; notes.address=message[i][1]; notes.mail=message[i][2]; notes.telephone=message[i][3]; EditDialog dlg=new EditDialog(this,"修改通讯录"); if(dlg.isOk){ message[i][0]=dlg.textName.getText(); message[i][1]=dlg.textAddress.getText(); message[i][2]=dlg.textEmail.getText(); message[i][3]=dlg.textTelephone.getText(); String s="姓名:"+message[i][0]+";\t地址"+message[i][1]+";\tE-mail"+message[i][2]+";\t电话"+message[i][3]; noteList.replaceItem(s,i); } dlg.dispose(); } }else if(e.getSource()==noteExit){ System.exit(0); } } private class WindowCloser extends WindowAdapter{ public void WindowClosing(WindowEvent we){ System.exit(0); } } public static void main(String[]args){ addressBook a=new addressBook(); } } class EditDialog extends Dialog implements ActionListener { private Button ok=new Button("确定"); private Button cancel=new Button("取消"); private Label labelName=new Label("姓名",Label.LEFT); private Label labelAddress=new Label("地址",Label.LEFT); private Label labelEmail=new Label("E-mail",Label.LEFT); private Label labelTelephone=new Label("电话",Label.LEFT); TextField textName=new TextField(30); TextField textAddress=new TextField(30); TextField textEmail=new TextField(30); TextField textTelephone=new TextField(30); public boolean isOk=false; private Info notes=new Info(); public EditDialog(Frame parent,String title){ super(parent,title,true); Panel pName=new Panel(); pName.setLayout(new FlowLayout()); pName.add(labelName); pName.add(textName); Panel pAddress=new Panel(); pName.setLayout(new FlowLayout()); pName.add(labelAddress); pName.add(textAddress); Panel pEmail=new Panel(); pName.add(labelEmail); pName.add(textEmail); Panel pTelephone=new Panel(); pName.add(labelTelephone); pName.add(textTelephone); Panel pInfo=new Panel(); pInfo.setLayout(new GridLayout(4,1)); pInfo.add(pName); pInfo.add(pAddress); pInfo.add(pEmail); pInfo.add(pTelephone); Panel pButton=new Panel(); pButton.setLayout(new FlowLayout()); pButton.add(ok); pButton.add(cancel); setLayout(new BorderLayout()); add("Center",pInfo); add("South",pButton); textName.setText(notes.name); textAddress.setText(notes.address); textEmail.setText(notes.mail); textTelephone.setText(notes.telephone); ok.addActionListener(this); cancel.addActionListener(this); addWindowListener(new WindowCloser()); setResizable(false); pack(); show(); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==ok){ isOk=true; this.hide(); } if(ae.getSource()==cancel){ isOk=false; this.hide(); } } private class WindowCloser extends WindowAdapter { public void windowClosing(WindowEvent we) { isOk=false; EditDialog.this.hide(); } } } class ConfirmDialog extends Dialog implements ActionListener { private Button okay=new Button("确定"); private Button cancel=new Button("取消"); private Label label=new Label(); public boolean close=false; public ConfirmDialog (Frame parent,String title,String question) { super(parent,title,true); label.setText(question); Panel buttons=new Panel(); buttons.setLayout(new FlowLayout()); buttons.add(okay); buttons.add(cancel); setLayout(new BorderLayout()); add("Center",label); add("South",buttons); okay.addActionListener(this); cancel.addActionListener(this); addWindowListener(new WindowCloser()); setResizable(false); pack(); show(); } private class WindowCloser extends WindowAdapter{ public void WindowClosing(WindowEvent we){ ConfirmDialog.this.close=false; ConfirmDialog.this.hide(); } public void actionPerformed(ActionEvent ae){ close=(ae.getSource()==okay); hide(); } }}

创新互联公司服务项目包括顺城网站建设、顺城网站制作、顺城网页制作以及顺城网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,顺城网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到顺城省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

输入3位数字 在通讯录中找到跟前3位数字相匹配的手机号码,用java怎么写代码?

楼上应该放出答案了,我这里只是用其他界面显示,不懂Swing的可以略过,(代码比较粗略,不一定符合规范,照搬需谨慎)

import java.awt.Dimension;

import java.awt.GridLayout;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.util.ArrayList;

import java.util.List;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class Demo extends JFrame {

ListString pnos = new ArrayListString();

public static void main(String[] args) {

new Demo();

}

public Demo() {

StringBuffer sb = new StringBuffer("htmlbody");

while (pnos.size()  15) {// "随机"生成电话号码,可以不理他

String telString = getRandomTel();

if (!pnos.contains(telString)) {

pnos.add(telString);

sb.append(telString);

if (pnos.size() % 3 == 0) {

sb.append("br/");

} else if (pnos.size()  15) {

sb.append(",");

}

}

}

sb.append("/body/html");

JLabel label = new JLabel(sb.toString());

final JTextField input = new JTextField();

final JLabel result = new JLabel();

this.setLayout(new GridLayout(3, 1));

this.add(label);

this.add(input);

this.add(result);

this.setSize(new Dimension(300, 500));

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.setLocationRelativeTo(null);

this.setVisible(true);

input.addKeyListener(new KeyAdapter() {

@Override

public void keyReleased(KeyEvent keyevent) {

result.setText(getMatchNo(input.getText()));

}

});

}

/**

 * 

 * @param perfix

 * @return

 */

public String getMatchNo(String perfix) {

StringBuffer sb = new StringBuffer("htmlbody");

if (perfix != null  !perfix.trim().equals(""))

for (String string : pnos) {// 这里是你要的部分,遍历“号码本”匹配是否为输入数字的开头

if (string.startsWith(perfix)) {

sb.append(string).append("br/");

}

}

sb.append("/body/html");

return sb.toString();

}

private static String[] telFirst = "134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153"

.split(",");

private static String getRandomTel() {

int index = getNum(0, telFirst.length - 1);

String first = telFirst[index];

String second = String.valueOf(getNum(1, 888) + 10000).substring(1);

String thrid = String.valueOf(getNum(1, 9100) + 10000).substring(1);

return first + second + thrid;

}

public static int getNum(int start, int end) {

return (int) (Math.random() * (end - start + 1) + start);

}

}

用JAVA编写一个班级通讯录

1)java form,jlable 、textField、button 神马 的 GridBagLayout布局搞一发

2)JDBC 往数据库搞一搞;

3)数据库排序取出,或者取出后代码排个序

4)步骤2已经写入数据库,下次从数据库区,不会丢失

5)搞一个方法,专门用于显示,每计算一次,调用这个方法

另;应该搞个登陆的,管理总要有权限控制的

Java编写一个班级通讯录

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class AddressList {

static Scanner scanner = new Scanner(System.in);

static ListEntity enlist = new ArrayListEntity();

public static void main(String[] args) {

int input;

AddressList addre = new AddressList();

System.out.println("===============欢迎使用**通讯录===============");

do{

System.out.println("1、插入联系人");

System.out.println("2、删除练习人");

System.out.println("3、修改联系人");

System.out.println("4、查询练习人");

System.out.println("5、查询全部联系人");

System.out.println("0、退出系统");

System.out.println("请选择:");

input = scanner.nextInt();

switch(input){

case 1:

Entity e = new Entity();

e.id = enlist.size();

System.out.println("请输入联系人姓名:");

e.name = scanner.next();

System.out.println("请输入联系方式:");

e.number = scanner.nextInt();

addre.add(e);

System.out.println("插入成功!");

break;

case 2:

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

int num = scanner.nextInt();

if(addre.delete(num))

System.out.println("删除成功!");

else

System.out.println("删除失败,请确认信息是否正确!");

break;

case 3:

System.out.println("请输入要修改人编号:");

int unum = scanner.nextInt();

addre.update(unum);

System.out.println("修改完成!");

break;

case 4:

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

String name = scanner.next();

Entity ent = addre.select(name);

if(ent!=null){

System.out.println(name+"的联系方式为:"+ent.number);

}else{

System.out.println("查无此人!");

}

break;

case 5:

for(Entity entit:enlist){

System.out.println(entit.name+"的联系方式为:"+entit.number);

}

break;

}

}while(input!=0);

System.out.println("谢谢使用!");

}

/*

 * 添加联系人

 */

public boolean add(Entity e){

enlist.add(e);

return true;

}

/*

 * 删除联系人

 */

public boolean delete(int num){

if(numenlist.size())

return false;

else

enlist.remove(num);

return true;

}

/*

 * 修改联系人

 */

public void update(int num){

if(numenlist.size())

System.out.println("查无此人!");

else{

Entity e = new Entity();

e.id = num;

System.out.println("请输入联系人姓名:");

e.name = scanner.next();

System.out.println("请输入联系方式:");

e.number = scanner.nextInt();

enlist.set(num, e);

}

}

/*

 * 查询指定联系人电话

 */

public Entity select(String name){

Entity en = null;

for(Entity e : enlist){

if(e.name.equals(name))

en = e;

}

return en;

}

}

class Entity{

public int id;//编号

public String name;//姓名

public int number;//联系电话

}

(java编程)采用双向链表作数据结构,编写一个通讯录管理系统。

#include

#include

#include

using namespace std;

#define SIZE 10

struct AddrList

{

string name;

string sex;

int age;

string QQ;

}addrlist[SIZE];

int main()

{

int i;

int j;

cout"输入要输入的记录数量:";

cini;

if (iSIZE)

{

cout"输入的记录数量大于顺序表的最大长度!"endl;

return 0;

}

cout"输入格式:\n姓名 性别 年龄 QQ\n"endl;

for (j=0;ji;++j)

{

cout"输入第"j+1"条记录"endl;

cinaddrlist[j].nameaddrlist[j].sexaddrlist[j].ageaddrlist[j].QQ;

}

cout"\n姓名\t性别\t年龄\tQQ"endl;

for (j=0;ji;++j)

{

coutaddrlist[j].name"\t"addrlist[j].sex"\t"addrlist[j].age"\t"addrlist[j].QQendl;

}

return 0;

}

输入:2

张三 男 23 123456

李四 女 24 66666

java通讯录全部代码!

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.Scanner;

public class AddList {

private String filePath = "";

private String bakPath = "";

private String content = "";

Scanner sc = new Scanner(System.in);

public String readFile(){

content = "";

if (isNull(filePath)) {

System.out.println("文件存储路径:");

filePath = sc.nextLine();

}

File file = new File(filePath);

FileReader fr = null;

try {

if (file.exists()) {

fr = new FileReader(file);

char[] chars = new char[1024];

int n = 0;

while((n = fr.read(chars)) != -1){

String string = new String(chars, 0, n);

content = content + string;

}

} else {

System.out.println("文件不存在");

}

} catch (Exception e) {

e.printStackTrace();

} finally {

if (fr != null) {

try {

fr.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

return content;

}

public void writeFile(String path){

File file = new File(path);

FileOutputStream fos = null;

mkDirs(path);

try {

fos = new FileOutputStream(file);

BufferedOutputStream bos = new BufferedOutputStream(fos);

PrintWriter pw = new PrintWriter(bos, true);

pw.print(content);

pw.flush();

} catch (FileNotFoundException e) {

e.printStackTrace();

} finally {

if (fos != null) {

try {

fos.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

public void writeFile(){

if (isNull(filePath)) {

System.out.println("文件存储路径:");

filePath = sc.nextLine();

}

File file = new File(filePath);

FileOutputStream fos = null;

mkDirs(filePath);

try {

fos = new FileOutputStream(file);

BufferedOutputStream bos = new BufferedOutputStream(fos);

PrintWriter pw = new PrintWriter(bos, true);

pw.print(content);

pw.flush();

} catch (FileNotFoundException e) {

e.printStackTrace();

} finally {

if (fos != null) {

try {

fos.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

public void mkDirs(String filepath){

if (filepath.indexOf("\\") != -1) {

filepath = filepath.replaceAll("\\", "/");

}

int n = filepath.indexOf("//");

String path = filepath.substring(0, n) + "//";

filepath = filepath.substring(filepath.indexOf("//") + 1, filepath.length());

String[] files = filepath.split("/");

for (int i = 0; i files.length - 1; i++) {

path = path + files[i];

File file = new File(path);

if (!file.exists()) {

file.mkdir();

}

}

}

public void addImfor(){

System.out.println("--------增加记录---------");

String name = "";

String tel = "";

String email = "";

content = readFile();

while(true){

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

name = sc.next();

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

tel = sc.next();

System.out.println("Email:");

email = sc.next();

content = content + name + "" + tel + "" + email +"==";

System.out.println("0、Exit 1、继续");

int i = sc.nextInt();

if (i == 0) {

break;

}

}

writeFile();

}

public void deleteImfor(){

System.out.println("---------删除记录---------");

String name = "";

String[] imfors = null;

content = readFile();

while(true){

System.out.println("你要删除的姓名是:");

name = sc.next();

if (content.indexOf(name) != -1) {

imfors = content.split("==");

for (int i = 0; i imfors.length; i++) {

if (imfors[i].indexOf(name) != -1) {

imfors[i] = "";

}

}


当前标题:java编写通讯录的代码,个人通讯录java代码
网页网址:http://bjjierui.cn/article/heipcp.html

其他资讯