java通讯录源代码.docx
《java通讯录源代码.docx》由会员分享,可在线阅读,更多相关《java通讯录源代码.docx(43页珍藏版)》请在冰点文库上搜索。
java通讯录源代码
学校:
江西农业大学
学院:
软件学院
班级:
1115
*******
课程设计名称:
JAVA程序通讯录
*******
日期:
2012年12月
江西农业大学软件学院
一、设计目的
随着计算机的普及,将通讯方式保存在计算机内已代替了纸质的通讯录。
通讯录保存在计算机中,便于分组,还便于增加、修改、删除好友信息。
本实训的做的内容为通讯录,里面涉及的类有MyFrame,zengjiazu,shuanchuzu,xiugaizu,chaxunzu,zengjiahaoyou,shanchun七个类,其中MyFrame是主界面类,它继承于JFrame
二、设计要求
1、对系统进行功能模块分析、功能模块分析正确;
2、系统设计要有经济价值,要实用;
3、编程简练,可用,功能全面,具有较好的健壮性;
4、系统界面外观和布局,可个性化设计,总体原则是“界面简洁、操作便捷”;
5、说明书、流程图要清楚;
6、应用程序打包发布。
三、设计内容
本次课程设计是开发一个简易的、小型的通讯录,我们命名为“通讯录”。
通讯录保存在计算机中,便于分组,还便于增加、修改、删除好友信息。
具体操作如下:
点击运行系统,进入主界面进行操作组和好友的操作;
点击组操作,进入界面,进行组添加,组修改,组删除以及退出的操作。
点击好友操作,进入界面,进行好友的添加,好友查询,好友修改,好友删除的操作。
组操作:
点击添加组的操作,进入界面,进行组的添加。
点击删除组的操作,进入界面,进行组的删除。
点击修改组名的操作,进入界面,进行组的修改。
好友操作:
点击好友添加的操作,进入界面,进行好友的添加。
点击好友查询的操作,进入界面,进行好友的查询。
点击好友删除的操作,进入界面,进行好友的删除。
点击好友修改信息的操作,进入界面,进行好友的修改信息。
四、设计思路
1.数据流图
2、详细设计
人机界面
a、主界面
b、增加组界面
C.删除组界面
d.修改组界面
e.查询好友界面
f.添加好友界面
3.通讯录运行过程
1.增加组
2.删除组
3.修改组
4.
e、增加好友
F.查询好友
G.修改好友
H.删除好友
附录:
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
publicclassMyFrameextendsJFrameimplementsActionListener{
JTextAreatxt;
JMenuBarmb;
JMenumenu1;
JMenumenu2;
JMenumenu3;
JButtonbtn1;
JButtonbtn2;
JLabelj1;
JMenuItemitem1;
JMenuItemitem2;
JMenuItemitem3;
JMenuItemitem4;
JMenuItemitem5;
JMenuItemitem6;
JMenuItemitem7;
JMenuItemitem8;
JMenuItemitem9;
JMenuItemitem10;
inti=0;
intk=0;
intj=0;
intm=0;
intt=0;
Stringstr[]=newString[100];
Stringstr1[]=newString[100];
Stringstr2[]=newString[100];
Stringstr3[]=newString[100];
Stringstr4[]=newString[100];
Booleanstr5[]=newBoolean[100];
Stringstr6[]=newString[100];
publicMyFrame(){
this.setTitle("通讯录");
this.setSize(300,500);
this.setLocation(200,100);
this.setLayout(null);
txt=newJTextArea(30,60);
JLabelj1=newJLabel();
btn1=newJButton("刷新");
btn2=newJButton("退出");
txt.setBounds(20,20,250,360);
btn1.setBounds(50,400,60,30);
btn2.setBounds(180,400,60,30);
j1.setBounds(80,120,100,150);
mb=newJMenuBar();
menu1=newJMenu("组操作");
item1=newJMenuItem("添加组");
item2=newJMenuItem("删除组");
item3=newJMenuItem("修改组");
item4=newJMenuItem("退出");
menu2=newJMenu("好友操作");
item5=newJMenuItem("查询好友");
item6=newJMenuItem("添加好友");
item7=newJMenuItem("修改好友");
item8=newJMenuItem("删除好友");
menu3=newJMenu("帮助");
mb.add(menu1);
mb.add(menu2);
mb.add(menu3);
menu1.add(item1);
menu1.add(item2);
menu1.add(item3);
menu1.add(item4);
menu2.add(item5);
menu2.add(item6);
menu2.add(item7);
menu2.add(item8);
this.setJMenuBar(mb);
this.add(txt);
this.add(btn1);
this.add(btn2);
this.add(j1);
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
item6.addActionListener(this);
item7.addActionListener(this);
item8.addActionListener(this);
btn2.addActionListener(this);
btn1.addActionListener(this);
this.setVisible(true);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==item1){
newzengjiazu();
}
if(e.getSource()==item2){
newshuanchuzu();
}
if(e.getSource()==item3){
newxiugaizu();
}
if(e.getSource()==item4){
System.exit(0);
}
if(e.getSource()==item5){
newchaxunzu();
}
if(e.getSource()==item6){
newzengjiahaoyou();
}
if(e.getSource()==item7){
newhaoxouxingming();
}
if(e.getSource()==item8){
newshanchun();
}
if(e.getSource()==btn2){
System.exit(0);
}
if(e.getSource()==btn1){
txt.setText("");
for(intf=0;f
txt.append(str[f]+"\n");
for(ints=0;sif(str[f].equals(str6[s])){
txt.append(""+str1[s]+"\n");
}
}
}
}
}
publicclasszengjiazuextendsJFrameimplementsActionListener{
JLabelj;
JTextFielduTxt;
JButtonbtn1,btn2;
zengjiazu(){
this.setSize(400,300);
this.setTitle("增加组");
this.setLayout(null);
j=newJLabel("组名");
uTxt=newJTextField(40);
btn1=newJButton("增加");
btn2=newJButton("退出");
j.setBounds(80,80,60,30);
uTxt.setBounds(130,80,130,30);
btn1.setBounds(120,200,60,30);
btn2.setBounds(200,200,60,30);
this.add(j);
this.add(uTxt);
this.add(btn1);
this.add(btn2);
btn2.addActionListener(this);
btn1.addActionListener(this);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==btn2){
this.dispose();
}
if(e.getSource()==btn1){
str[i]=uTxt.getText();
txt.setText(txt.getText()+"\n"+str[i]);
i++;
this.dispose();
}
}
}
publicclassshuanchuzuextendsJFrameimplementsActionListener{
JLabelj;
JTextFielduTxt;
JButtonbtn1,btn2;
shuanchuzu(){
this.setSize(400,300);
this.setTitle("删除组");
this.setLayout(null);
j=newJLabel("组名");
uTxt=newJTextField(20);
btn1=newJButton("删除");
btn2=newJButton("退出");
j.setBounds(110,100,60,26);
uTxt.setBounds(150,100,100,26);
btn1.setBounds(100,200,60,30);
btn2.setBounds(210,200,60,30);
this.add(j);
this.add(uTxt);
this.add(btn1);
this.add(btn2);
btn2.addActionListener(this);
btn1.addActionListener(this);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==btn2){
this.dispose();
}
if(e.getSource()==btn1){
for(intt=0;t
if(str[t].equals(uTxt.getText())){
str[t]=str[t+1];
i--;
}
}
this.dispose();
}
}
}
publicclassxiugaizuextendsJFrameimplementsActionListener{
JLabelj1,j2;
JTextFieldtxt1,txt2;
JButtonbtn1,btn2;
xiugaizu(){
this.setSize(400,300);
this.setTitle("修改组");
this.setLayout(null);
j2=newJLabel("新组名");
j1=newJLabel("原组名");
txt1=newJTextField(20);
txt2=newJTextField(20);
btn1=newJButton("修改");
btn2=newJButton("退出");
j2.setBounds(80,80,60,26);
j1.setBounds(80,40,60,26);
txt1.setBounds(130,40,130,26);
txt2.setBounds(130,80,130,26);
btn1.setBounds(120,200,60,30);
btn2.setBounds(200,200,60,30);
this.add(j1);
this.add(j2);
this.add(txt1);
this.add(txt2);
this.add(btn1);
this.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==btn2){
this.dispose();
}
if(e.getSource()==btn1){
for(intt=0;t
if(txt1.getText().equals(str[t])){
str[t]=txt2.getText();
str6[t]=txt2.getText();
}
this.dispose();
}
}
}
}
publicclasschaxunzuextendsJFrameimplementsActionListener{
JLabelj1;
JTextFielduTxt;
JButtonbtn1,btn2;
chaxunzu(){
this.setSize(400,300);
this.setTitle("查询好友");
this.setLayout(null);
j1=newJLabel("好友名");
uTxt=newJTextField(20);
btn1=newJButton("查询");
btn2=newJButton("退出");
j1.setBounds(100,100,60,30);
uTxt.setBounds(150,100,120,30);
btn1.setBounds(100,200,60,30);
btn2.setBounds(220,200,60,30);
this.add(j1);
this.add(uTxt);
this.add(btn1);
this.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==btn2){
this.dispose();
}
if(e.getSource()==btn1){
for(intf=0;fif(uTxt.getText().equals(str1[f])){
t=f;
newhaoyouxinxi(t);
}
}
this.dispose();
}
}
}
publicclasszengjiahaoyouextendsJFrameimplementsActionListener,ItemListener{
JLabelj1,j2,j3,j4,j5;
JTextFieldtxt1,txt2,txt3,txt4;
JButtonbtn1,btn2;
JLabelsex=newJLabel("性别");
JRadioButtonr1,r2;
Choicec;
zengjiahaoyou(){
this.setSize(450,600);
this.setTitle("增加好友");
this.setLayout(null);
j1=newJLabel("姓名");
j2=newJLabel("手机");
j3=newJLabel("电话");
j4=newJLabel("地址");
j5=newJLabel("归属组");
txt1=newJTextField(20);
txt2=newJTextField(20);
txt3=newJTextField(20);
txt4=newJTextField(20);
r1=newJRadioButton("男");
r2=newJRadioButton("女");
ButtonGroupbg=newButtonGroup();
bg.add(r1);
bg.add(r2);
btn1=newJButton("提交");
btn2=newJButton("取消");
j1.setBounds(80,50,60,26);
j2.setBounds(80,100,60,26);
j3.setBounds(80,150,60,26);
j4.setBounds(80,200,60,26);
j5.setBounds(80,250,60,26);
//cb.setBounds(120,250,180,26);
c=newChoice();
c.setBounds(120,250,180,26);
for(intt=0;t
c.add(str[t]);
}
txt1.setBounds(120,50,180,26);
txt2.setBounds(120,100,