⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressentry.java

📁 java图形化界面编程 功能和记事本通讯录相似 记录通讯人的姓名和联系方法等信息并提供查询
💻 JAVA
字号:
package elegate.cn.edu.nju;

import java.io.*;
import java.util.*;
import javax.swing.ImageIcon;

/**
 * a class describe an address entry
 * @author Elegate,elegate@gmail.com
 * @author cs department @SuppressWarnings("serial")
of NJU
 * @version 1.0
 */
final public class AddressEntry implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * default birthday if no birthday provided
	 */
	public GregorianCalendar DEFAULT_BIRTHDAY=new GregorianCalendar(1984,9,19);
	/**
	 * the name of the address entry
	 */
	private String name;
	/**
	 * the nickname of the address entry
	 */
	private String nickname;
	
	/**
	 * the sex for the address entry
	 */
	private String sex;
	/**
	 * the profession of the address entry
	 */
	private String profession;
	/**
	 * the mobile phone of the address entry
	 */
	private String mobilePhone;
	/**
	 * the home telephone of the address entry
	 */
	private String homeTelephone;
	/**
	 * the office telephone of the address entry
	 */
	private String officeTelephone;
	/**
	 * the birthday of the address entry
	 */
	private GregorianCalendar birthday;
	/**
	 * the email of the address entry
	 */
	private String email;
	/**
	 * the city of the address entry
	 */
	private String city;
	/**
	 * the image id of the address entry
	 */
	private int imageId;
	/**
	 * the id of the address entry
	 */
	private final long id;
	/**
	 * the groups the address entry belongs to
	 */
	private ArrayList<GroupEntry> groupsBelongsTo;
	
	
	
	/**
	 * a constructor with all attributes considered
	 * @param name 				the name of the address entry
	 * @param nickname 			the nickname of the address entry
	 * @param sex				the sex of the address entry
	 * @param profession 		the profession of the address entry
	 * @param mobilePhone 		the mobile phone of the address entry
	 * @param homeTelephone 	the home telephone of the address entry
	 * @param officeTelephone 	the office telephone of the address entry
	 * @param birthday 			the birthday of the address entry
	 * @param email 			the email of the address entry
	 * @param city 				the city of the address entry
	 * @param imageId			the image id of the address entry
	 * @param group 			the group the address entry belongs to
	 * 
	 */
	public AddressEntry(String name,String nickname,String sex
			,String mobilePhone,String homeTelephone
			,String officeTelephone,GregorianCalendar birthday
			,String email,int imageId,String profession
			,String city,GroupEntry group)
	{
		this.groupsBelongsTo=new ArrayList<GroupEntry>();
		this.id=System.currentTimeMillis();
		
		this.setAddressEntry(name,nickname,sex,mobilePhone
				,homeTelephone,officeTelephone,birthday
				,email,imageId,profession,city,group);
		
	}
	
	/**
	 * set the address entry with new values
	* @param name 				the new name of the address entry
	 * @param nickname 			the new nickname of the address entry
	 * @param sex				the sex of the address entry
	 * @param profession 		the new profession of the address entry
	 * @param mobilePhone 		the new mobile phone of the address entry
	 * @param homeTelephone 	the new home telephone of the address entry
	 * @param officeTelephone 	the new office telephone of the address entry
	 * @param birthday 			the new birthday of the address entry
	 * @param email 			the new email of the address entry
	 * @param city 				the new city of the address entry
	 * @param group 			the new group the address entry belongs to
	 */
	public void setAddressEntry(String name,String nickname,String sex
			,String mobilePhone,String homeTelephone
			,String officeTelephone,GregorianCalendar birthday
			,String email,int imageId,String profession
			,String city,GroupEntry group)
	{
		this.name=name;
		this.nickname= nickname!=null? nickname:"";
		this.sex=sex;
		this.profession= profession!=null? profession:"";
		this.mobilePhone= mobilePhone!=null? mobilePhone:"";
		this.homeTelephone= homeTelephone!=null? homeTelephone:"";
		this.officeTelephone= officeTelephone!=null? officeTelephone:"";
		this.birthday= birthday!=null? birthday:DEFAULT_BIRTHDAY;
		this.email= email!=null? email:"";
		this.city= city!=null? city:"";
		this.imageId=imageId;
		if(group!=null)
			this.groupsBelongsTo.add(group);
	}
	/**
	 * get the groups this address entry belongs to
	 * @return the groups this address entry belongs to
	 */
	public ArrayList<GroupEntry> getGroupsBelongsTo()
	{
		return this.groupsBelongsTo;
	}
	
	/**
	 * join a group
	 * @param group the group to be joined
	 * @see #quitGroup(GroupEntry)
	 */
	public void joinGroup(GroupEntry group)
	{
		if(group!=null && !this.groupsBelongsTo.contains(group))
		{
			this.groupsBelongsTo.add(group);
		}
	}
	
	/**
	 * quit a group
	 * @param group the group to quit
	 * @see #joinGroup(GroupEntry)
	 */
	public void quitGroup(GroupEntry group)
	{
		this.groupsBelongsTo.remove(group);
	}
	
	/**
	 * get name of the address entry 
	 * @return the name of the address entry
	 * @see #setName(String)
	 */
	public String getName()
	{
		return this.name;
	}
	
	/**
	 * set the name of the address entry 
	 * @param name the new name of the address entry
	 * @see #getName()
	 */
	public void setName(String name)
	{
		if(name!=null && name.length()!=0)
			this.name=name;
	}
	
	/**
	 * get the nickname of the address entry
	 * @return the nickname of the address entry
	 * @see #setNickname(String)
	 */
	public String getNickname()
	{	
		return this.nickname;
	}
	/**
	 * set the nickname of the address entry
	 * @param nickname the new nickname of the address entry
	 * @see #getNickname()
	 */
	public void setNickname(String nickname)
	{
		if(nickname!=null && nickname.length()!=0)
			this.nickname=nickname;
	}
	/**
	 * get the sex of the address entry
	 * @return the sex of the address entry
	 * @see #setSex(String)
	 */
	public String getSex()
	{
		return this.sex;
	}
	
	/**
	 * set the sex of the address entry
	 * @param sex the sex of the address entry
	 * @see #getSex()
	 */
	public void setSex(String sex)
	{
		this.sex=sex;
	}
	
	/**
	 * the profession of the address entry
	 * @return the profession of the address entry
	 * @see #setProfession(String)
	 */
	public String getProfession()
	{
		return this.profession;
	}
	
	/**
	 * set the profession of the address entry
	 * @param profession the new profession of the address entry
	 * @see #getProfession()
	 */
	public void setProfession(String profession)
	{
		if(profession!=null && profession.length()!=0)
			this.profession=profession;
	}
	
	/**
	 * get the mobile phone of the address entry
	 * @return the mobile phone of the address entry
	 * @see #setMobilePhone(String)
	 */
	public String getMobilePhone()
	{
		return this.mobilePhone;
	}
	
	/**
	 * set the mobile phone of the address entry
	 * @param mobilePhone the new mobile phone of the address entry
	 * @see #getMobilePhone()
	 */
	public void setMobilePhone(String mobilePhone)
	{
		if(mobilePhone!=null && mobilePhone.length()!=0)
			this.mobilePhone=mobilePhone;
	}
	
	/**
	 * get the home telephone of the address entry
	 * @return the home telephone of the address entry
	 * @see #setHomeTelephone(String)
	 */
	public String getHomeTelephone()
	{
		return this.homeTelephone;
	}
	/**
	 * set the home telephone of the address entry
	 * @param homeTelephone the new home telephone of the address entry
	 * @see #getHomeTelephone()
	 */
	public void setHomeTelephone(String homeTelephone)
	{
		if(homeTelephone!=null && homeTelephone.length()!=0)
			this.homeTelephone=homeTelephone;
	}
	
	/**
	 * get the office telephone of the address entry
	 * @return the office telephone of the address entry
	 * @see #setOfficeTelephone(String)
	 */
	public String getOfficeTelephone()
	{
		return this.officeTelephone;
	}
	
	/**
	 * set the office telephone of the address entry
	 * @param officeTelephone the new offic telephone of the address entry
	 * @see #getOfficeTelephone()
	 */
	public void setOfficeTelephone(String officeTelephone)
	{
		if(officeTelephone!=null && officeTelephone.length()!=0)
			this.officeTelephone=officeTelephone;
	}
	/**
	 * get the birthday of the address entry
	 * @return the birthday of the address entry
	 * @see #setBirthday(GregorianCalendar) 
	 */
	public GregorianCalendar getBirthday()
	{
		return this.birthday;
	}
	/**
	 * set the birthday of the address entry
	 * @param birthday the new birthday of the address entry
	 * @see #getBirthday()
	 */
	public void setBirthday(GregorianCalendar birthday)
	{
		if(birthday!=null)
			this.birthday=birthday;
	}
	
	/**
	 * get the email of the address entry 
	 * @return the email address
	 * @see #setEmail(String)
	 */
	public String getEmail()
	{
		return this.email;
	}
	
	/**
	 * set the email of the address entry
	 * @param email the new email address
	 * @see #getEmail()
	 */
	public void setEmail(String email)
	{
		if(email!=null && email.length()!=0)
			this.email=email;
	}
	/**
	 * get the city of the address entry
	 * @return the city of the address entry
	 * @see #setCity(String)
	 */
	public String getCity()
	{
		return this.city;
	}
	/**
	 * set the city of the address entry
	 * @param city the new city of the address entry
	 * @see #getCity()
	 */
	public void setCity(String city)
	{
		if(city!=null && city.length()!=0)
			this.city=city;
	}
	/**
	 * get the image id of the entry
	 * @return the image id
	 */
	public int getImageId()
	{
		return this.imageId;
	}
	
	/**
	 * set the image id of the address entry
	 * @param imageId the new image id
	 */
	public void setImageId(int imageId)
	{
		this.imageId=imageId;
	}
	
	/**
	 * get the ID of the address entry
	 * @return the ID of the address entry
	 */
	public long getID()
	{
		return this.id;
	}
	
	/**
	 * overridden method <strong>equals</strong> 
	 */
	public boolean equals(Object obj)
	{
		if(obj==this)
			return true;
		if(obj==null)
			return false;
		if(this.getClass()!=obj.getClass())
			return false;
		AddressEntry add=(AddressEntry)obj;
		return this.id==add.id;
	}
	/**
	 * overridden method <strong>toString</strong>
	 */
	public String toString()
	{
		return this.getClass().getName()+"[name="+this.name
		+",nickname="+this.nickname+",profession="+this.profession
		+",mobilePhone="+this.mobilePhone+",homeTelephone="+this.homeTelephone
		+",officeTelephone="+this.officeTelephone+",birthday="+this.birthday
		+",email="+this.email+",Icon="+imageId+",city="+this.city+",ID="+this.id+"]";
	}
	
	public Object[] toArray()
	{
		Object[] obj=new Object[13];
		obj[0]=new Boolean(false);
		obj[1]=name;
		obj[2]=nickname;
		obj[3]=sex;
		obj[4]=mobilePhone;
		obj[5]=homeTelephone;
		obj[6]=officeTelephone;
		obj[7]=birthday.getTime();//dateFormat.format(birthday.getTime());
		obj[8]=email;
		obj[9]=new ImageIcon("config"+File.separator
				+"face"+File.separator+imageId+"-1.gif");
		obj[10]=profession;
		obj[11]=city;
		obj[12]=new Long(id);
		return obj;
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -