完整word版个人通讯录管理系统源代码.docx
- 文档编号:28910465
- 上传时间:2023-07-20
- 格式:DOCX
- 页数:20
- 大小:18.47KB
完整word版个人通讯录管理系统源代码.docx
《完整word版个人通讯录管理系统源代码.docx》由会员分享,可在线阅读,更多相关《完整word版个人通讯录管理系统源代码.docx(20页珍藏版)》请在冰豆网上搜索。
完整word版个人通讯录管理系统源代码
个人通讯录管理系统
importjavax。
swing。
*;
importjava。
awt.*;
importjava。
awt.event。
*;
importjava.io.*;
publicclassTongXunLu{
publicstaticvoidmain(String[]args){
newmenu();
}
}
classmenuimplementsActionListener{
JMenuItemzengjia,suoyou,beifen,quit,select,del;
JFramef;
Containercon;
JMenuBarbar;
Stringstr1,str2,str3;
JFileChooserfc1=newJFileChooser();
Filefc2=newFile("D:
//test。
txt”);
menu(){
f=newJFrame(”通讯录管理系统");
f。
setDefaultCloseOperation(JFrame。
DISPOSE_ON_CLOSE);
f。
setSize(500,400);
f。
setLocation(130,150);
con=f。
getContentPane();
Colorc=Color。
YELLOW;
Fontfo=newFont("黑体",Font.BOLD,40);
JPanelpan=newJPanel();
JLabellab=newJLabel(”通讯录管理系统");
lab.setForeground(c);
lab.setFont(fo);
pan.add(lab);
con。
add(pan);
bar=newJMenuBar();
f。
setJMenuBar(bar);
JMenumenu1=newJMenu("文件");
JMenumenu2=newJMenu(”查询");
JMenumenu3=newJMenu("删除");
zengjia=newJMenuItem("增加记录");
suoyou=newJMenuItem(”所有记录”);
beifen=newJMenuItem(”文件备份”);
quit=newJMenuItem(”退出");
select=newJMenuItem(”查询");
del=newJMenuItem("删除");
menu1.add(zengjia);
menu1。
add(suoyou);
menu1.add(beifen);
menu1。
addSeparator();
menu1。
add(quit);
menu2。
add(select);
menu3。
add(del);
zengjia。
addActionListener(this);
suoyou。
addActionListener(this);
beifen.addActionListener(this);
quit。
addActionListener(this);
select。
addActionListener(this);
del.addActionListener(this);
bar。
add(menu1);
bar。
add(menu2);
bar。
add(menu3);
f。
setVisible(true);
}
publicFilegetFile(){
intret=fc1。
showSaveDialog(null);
if(ret==JFileChooser。
APPROVE_OPTION){
returnfc1.getSelectedFile();
}
returnnull;
}
publicvoidactionPerformed(ActionEventevt){
if(evt.getSource()==quit)System.exit(0);
if(evt.getSource()==zengjia){
f.dispose();
newxinjian();
}
if(evt。
getSource()==suoyou){
f。
dispose();
newsuoyou();}
if(evt.getSource()==beifen){
char[]ss=newchar[1];
try{
FileReaderinput=newFileReader(”D:
//test.txt");
FileWriteroutput=newFileWriter(”D:
//un.txt",true);
while(input.read(ss,0,1)!
=—1)
output。
write(ss);
input。
close();
output。
close();
}catch(IOExceptione){
e.printStackTrace();
}
JOptionPane.showMessageDialog(null,”你确定要备份么?
”);
}
if(evt.getSource()==select){
f.dispose();
newselect();}
if(evt。
getSource()==del){
f.dispose();
newdel();}
}
}
classxinjianextendsmenuimplementsActionListener{
JTextFieldtf1,tf2,tf3,tf4;
JButtonbt;
xinjian(){
bt=newJButton("确认");
BorderLayoutl1=newBorderLayout();
JPanelpan=newJPanel();
JPanelpan2=newJPanel();
JPanelpan3=newJPanel();
JPanelpan4=newJPanel();
JPanelpan5=newJPanel();
JPanelpan6=newJPanel();
con.setLayout(l1);
GridLayoutg=newGridLayout(5,1);
Colorc=Color。
yellow;
Fontfo=newFont("黑体",Font.BOLD,40);
JPanelpanl=newJPanel();
JLabellab1=newJLabel(”通讯录管理系统”);
lab1。
setForeground(c);
lab1。
setFont(fo);
pan.add(lab1);
JLabellab2=newJLabel(”姓名");
tf1=newJTextField(10);
JLabellab3=newJLabel("电话");
tf2=newJTextField(10);
JLabellab4=newJLabel("e—mile”);
tf3=newJTextField(10);
JLabellab5=newJLabel("qq”);
tf4=newJTextField(10);
panl。
add(lab1);
pan。
setLayout(g);
pan2.add(lab2);pan2。
add(tf1);
pan3.add(lab3);pan3.add(tf2);
pan4.add(lab4);pan4。
add(tf3);
pan5.add(lab5);pan5。
add(tf4);
pan6.add(bt);
tf1。
addActionListener(this);
tf2。
addActionListener(this);
tf3.addActionListener(this);
tf4.addActionListener(this);
bt。
addActionListener(this);
pan。
add(pan2);pan.add(pan3);
pan。
add(pan4);pan.add(pan5);
pan。
add(pan6);
con.add(BorderLayout。
NORTH,panl);
con。
add(BorderLayout。
CENTER,pan);
}
publicvoidactionPerformed(ActionEventevt){
if(evt。
getSource()==quit)System。
exit(0);
if(evt.getSource()==zengjia){
f。
dispose();
newxinjian();}
if(evt。
getSource()==suoyou){
f.dispose();
newsuoyou();}
if(evt。
getSource()==beifen){
char[]ss=newchar[1];
try{
FileReaderinput=newFileReader(”D:
//test.txt”);
FileWriteroutput=newFileWriter("D:
//un。
txt",true);
while(input。
read(ss,0,1)!
=-1)
output.write(ss);
input.close();
output.close();
}catch(IOExceptione){
e.printStackTrace();
}
f。
dispose();
JOptionPane。
showMessageDialog(null,”你确定要备份么?
”);
}
if(evt。
getSource()==select){
f.dispose();newselect();}
if(evt。
getSource()==del){newdel();}
if(evt。
getSource()==bt)
{
Stringstr;
str1=tf1.getText();
str2=tf2.getText();
str3=tf3。
getText();
Stringstr4=tf4.getText();
try{
FileWriterfos1=newFileWriter("D:
\\un。
txt”,true);
BufferedWriteroutput=newBufferedWriter(fos1);
str=str1+”"+str2+””+str3+""+str4;
output。
write(str);
output。
write("\n");
output.close();
}catch(IOExceptione){
e。
printStackTrace();
}
JOptionPane。
showMessageDialog(null,”添加成功!
");
tf1.setText("");
tf2。
setText("");
tf3.setText("");
}
}
}
classsuoyouextendsmenuimplementsActionListener{
JTextAreata=newJTextArea(5,5);
char[]ss=newchar[1];
Stringstr;
suoyou(){
BorderLayoutgr=newBorderLayout();
con.setLayout(gr);
JPanelpan=newJPanel();
pan.setLayout(newGridLayout(1,3));
JLabellab1=newJLabel("姓名");
JLabellab2=newJLabel(”电话”);
JLabellab3=newJLabel(”e—mile");
JLabellab4=newJLabel("qq”);
pan。
add(lab1);
pan.add(lab2);
pan.add(lab3);
pan。
add(lab4);
try{
FileReaderfile=newFileReader(”D:
//un。
txt");
while(file。
read(ss,0,1)!
=—1)
ta.append(String。
valueOf(ss));
}catch(IOExceptione){
e。
printStackTrace();
}
con.add(BorderLayout.NORTH,pan);
con。
add(BorderLayout.CENTER,ta);
}
publicvoidactionPerformed(ActionEventevt){
if(evt。
getSource()==quit)System。
exit(0);
if(evt.getSource()==zengjia){
f.dispose();
newxinjian();}
if(evt.getSource()==suoyou){
f.dispose();
newsuoyou();}
if(evt。
getSource()==beifen){
char[]ss=newchar[1];
try{
FileReaderinput=newFileReader("D:
//test。
txt”);
FileWriteroutput=newFileWriter(”D:
//un。
txt”,true);
while(input.read(ss,0,1)!
=—1)
output。
write(ss);
input.close();
output。
close();
}catch(IOExceptione){
e.printStackTrace();
}
f.dispose();
JOptionPane。
showMessageDialog(null,”你确定要备份么?
”);
}
if(evt.getSource()==select){
f.dispose();
newselect();}
if(evt.getSource()==del){
f.dispose();
newdel();}
}
}
classselectextendsmenu{
JTextFieldtf;
JButtonbt1;
JTextAreata=newJTextArea(50,54);
select(){
BorderLayoutl=newBorderLayout();
con。
setLayout(l);
JPanelpan=newJPanel();
JPanelpan1=newJPanel();
JLabellab=newJLabel(”姓名");
tf=newJTextField(10);
bt1=newJButton("确定");
pan.add(lab);
tf=newJTextField(10);
pan。
add(tf);
pan。
add(bt1);
JLabellab1=newJLabel(”姓名”);
pan1.add(lab1);
JLabellab2=newJLabel("电话”);
pan1.add(lab2);
JLabellab3=newJLabel("e-mile");
pan1.add(lab3);
JLabellab4=newJLabel("qq");
pan1.add(lab4);
pan1.add(ta);
bt1.addActionListener(this);
con.add(BorderLayout。
NORTH,pan);
con。
add(BorderLayout。
CENTER,pan1);
}
publicvoidactionPerformed(ActionEventevt){
if(evt.getSource()==quit)System。
exit(0);
if(evt。
getSource()==zengjia){
f。
dispose();
newxinjian();}
if(evt.getSource()==suoyou){
f。
dispose();
newsuoyou();}
if(evt.getSource()==beifen){
char[]ss=newchar[1];
try{
FileReaderinput=newFileReader("D:
//test。
txt”);
FileWriteroutput=newFileWriter("D:
//un。
txt”,true);
while(input。
read(ss,0,1)!
=—1)
output.write(ss);
input.close();
output。
close();
}catch(IOExceptione){
e.printStackTrace();
}
f.dispose();
JOptionPane。
showMessageDialog(null,”你确定要备份么?
");
}
if(evt.getSource()==select){
f.dispose();
newselect();}
if(evt.getSource()==del){
f.dispose();
newdel();}
if(evt。
getSource()==bt1){
Stringstr4,str5;
str4=tf。
getText();
try{
FileReaderreader=newFileReader("D:
\\un.txt");
BufferedReaderinput=newBufferedReader(reader);
str5=input。
readLine();
while(!
str5。
startsWith(str4))
{
str5=input.readLine();
if(str5==null){
JOptionPane.showMessageDialog(null,"没有找到该人!
");
break;
}
}
if(str5!
=null&&str5。
startsWith(str4))
{
ta.setText(str5);
}
input.close();
}catch(IOExceptione){
e.printStackTrace();
}
tf。
setText(””);
}
}
}
classdelextendsmenuimplementsActionListener{
JTextFieldtf;
JButtonbt2;
JTextAreata=newJTextArea(15,54);
del(){
BorderLayoutl=newBorderLayout();
con。
setLayout(l);
JPanelpan=newJPanel();
JPanelpan1=newJPanel();
JLabellab=newJLabel(”姓名");
tf=newJTextField(10);
bt2=newJButton(”确认”);
JLabellab1=newJLabel("姓名");
JLabellab2=newJLabel("电话”);
JLabellab3=newJLabel("e-mile");
JLabellab4=newJLabel("qq”);
tf=newJTextField(10);
pan.add(lab);
pan.add(tf);
pan.add(bt2);
bt2。
addActionListener(this);
pan。
add(lab);
pan.add(tf);
pan1。
add(lab1);pan1.add(lab2);pan1.add(lab3);pan1.add(lab4);
pan1。
add(ta);
con.add(BorderLayout。
NORTH,pan);
con.add(BorderLayout.CENTER,pan1);
}
publicvoidactionPerformed(ActionEventevt){
if(evt。
getSource()==quit)System。
exit(0);
if(evt。
getSource()==zengjia){
f.dispose();
newxinjian();}
if(evt。
getSource()==suoyou){
f。
dispose();
newsuoyou();}
if(evt。
getSource()==beifen){
char[]ss=newchar[1];
try{
FileReaderinput=newFileReader(”D:
//tes
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 完整 word 个人 通讯录 管理 系统 源代码