RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
java电话簿源代码,java实现电话簿

java的电话簿程序

==================================

创新互联建站是专业的天桥网站建设公司,天桥接单;提供成都网站制作、网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行天桥网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

public class PhoneBook {

// 代表有多少条记录

private int size = 0;

// 用来记录信息的数组

private Phone[] phones = new Phone[100];

private String filename = "phonebook.txt";

public PhoneBook() {

try {

read();

} catch (IOException e) {

}

}

private void read() throws IOException {

File f = new File(filename);

if (!f.exists()) {

return;

}

BufferedReader br = new BufferedReader(new FileReader(filename));

String line = null;

while ((line = br.readLine()) != null) {

if (line.trim().length() 0) {

Phone phone = new Phone(line);

addPhone(phone);

}

}

br.close();

}

public void store() throws IOException {

File f = new File(filename);

BufferedWriter bw = new BufferedWriter(new FileWriter(filename));

for (Phone phone : phones) {

if (phone == null) {

continue;

}

String str = phone.name + "::" + phone.number + "::" + phone.notes;

bw.write(str + "\r\n");

}

bw.close();

}

public void addPhone(Phone phone) {

phones[size++] = phone;

}

public Phone getPhone(String name) {

for (Phone phone : phones) {

if (phone == null) {

continue;

}

if (phone.name.equalsIgnoreCase(name)) {

return phone;

}

}

return null;

}

public Phone[] getPhones() {

return phones;

}

}

class Phone {

String name, number, notes;

public Phone() {

}

public Phone(String line) {

String[] strs = line.split("::");

name = strs[0];

number = strs[1];

notes = strs[2];

}

public String toString() {

return String.format("-- %s\r\n-- %s\r\n-- %s", name, number, notes);

}

}

=================================================

import java.io.IOException;

import java.util.Scanner;

public class MainClass {

private static PhoneBook book = new PhoneBook();

public static void main(String[] args) {

getCommand();

}

public static void getCommand() {

String cmd = getString("Command: ");

if (cmd.startsWith("e ")) {

add(cmd.substring(cmd.indexOf(' ') + 1));

try {

book.store();// 添加一个就记录一次文件

} catch (IOException e) {

e.printStackTrace();

}

} else if (cmd.startsWith("f ")) {

find(cmd.substring(cmd.indexOf(' ') + 1));

} else if (cmd.equals("l")) {

list();

} else if (cmd.startsWith("q")) {

quit();

} else {

System.out.println("unknown command!");

}

getCommand();

}

public static void add(String name) {

Phone phone = new Phone();

phone.name = convert(name);// 名字转换

phone.number = getString("Enter number: ");

phone.notes = getString("Enter notes: ");

book.addPhone(phone);

}

public static void find(String name) {

Phone phone = book.getPhone(name);

if (phone != null) {

System.out.println(phone);

} else {

System.out.println("** No entry with code " + name);

}

}

public static void list() {

for (Phone phone : book.getPhones()) {

if (phone != null) {

System.out.println(phone);

}

}

}

public static void quit() {

try {

book.store();

} catch (IOException e) {

}

System.exit(0);

}

public static String getString(String tip) {

System.out.print(tip);

Scanner sc = new Scanner(System.in);

return sc.nextLine();

}

private static String convert(String name) {

if (name != null name.length() 0) {

return name.substring(0, 1).toUpperCase()

+ name.substring(1).toLowerCase();

}

return null;

}

}

java小型通讯录源代码

package src;

public class TelBook {

// 姓名

String name;

// 家庭电话

Integer homePhone;

// 个人移动电话

Integer personalMobilePhone;

// 办公电话

Integer officePhone;

// 家庭地址

String homeAddress;

// 办公地址

String officeAddress;

// QQ号码

Integer qqNumber;

// MSN号码

String msn;

// 邮件

String email;

// 备注

String notes;

String getEmail() {

return email;

}

void setEmail(String email) {

this.email = email;

}

String getHomeAddress() {

return homeAddress;

}

void setHomeAddress(String homeAddress) {

this.homeAddress = homeAddress;

}

Integer getHomePhone() {

return homePhone;

}

void setHomePhone(Integer homePhone) {

this.homePhone = homePhone;

}

String getMsn() {

return msn;

}

void setMsn(String msn) {

this.msn = msn;

}

String getName() {

return name;

}

void setName(String name) {

this.name = name;

}

String getNotes() {

return notes;

}

void setNotes(String notes) {

this.notes = notes;

}

String getOfficeAddress() {

return officeAddress;

}

void setOfficeAddress(String officeAddress) {

this.officeAddress = officeAddress;

}

Integer getOfficePhone() {

return officePhone;

}

void setOfficePhone(Integer officePhone) {

this.officePhone = officePhone;

}

Integer getPersonalMobilePhone() {

return personalMobilePhone;

}

void setPersonalMobilePhone(Integer personalMobilePhone) {

this.personalMobilePhone = personalMobilePhone;

}

Integer getQqNumber() {

return qqNumber;

}

void setQqNumber(Integer qqNumber) {

this.qqNumber = qqNumber;

}

public TelBook() {

}

public TelBook(String name, Integer personalMobilePhone) {

this.setName(name);

this.setPersonalMobilePhone(personalMobilePhone);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

TelBook myfriend = new TelBook("张三", new Integer("13800138000"));

}

}

用JAVA写一个通讯录,怎么写。源代码。

采用C/S的架构方式。

首先用swing 画几个条条框框出来。做出显示 和 添加 修改的界面。

添加的时候。吧输入的信息存入数据库

修改的时候 修改数据库里面的内容

查询的时候 显示数据库里面的内容。

不想用数据库 也可以吧文件写在磁盘上。不过这样,还不如用个excel当通讯录用来的省事。

这就是high level。detail么 自己研究吧


新闻名称:java电话簿源代码,java实现电话簿
URL地址:http://lswzjz.com/article/dscsghd.html