通讯录java.docx

上传人:b****1 文档编号:324059 上传时间:2023-04-28 格式:DOCX 页数:15 大小:17.55KB
下载 相关 举报
通讯录java.docx_第1页
第1页 / 共15页
通讯录java.docx_第2页
第2页 / 共15页
通讯录java.docx_第3页
第3页 / 共15页
通讯录java.docx_第4页
第4页 / 共15页
通讯录java.docx_第5页
第5页 / 共15页
通讯录java.docx_第6页
第6页 / 共15页
通讯录java.docx_第7页
第7页 / 共15页
通讯录java.docx_第8页
第8页 / 共15页
通讯录java.docx_第9页
第9页 / 共15页
通讯录java.docx_第10页
第10页 / 共15页
通讯录java.docx_第11页
第11页 / 共15页
通讯录java.docx_第12页
第12页 / 共15页
通讯录java.docx_第13页
第13页 / 共15页
通讯录java.docx_第14页
第14页 / 共15页
通讯录java.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

通讯录java.docx

《通讯录java.docx》由会员分享,可在线阅读,更多相关《通讯录java.docx(15页珍藏版)》请在冰点文库上搜索。

通讯录java.docx

通讯录java

需要建五个.java然后才可以运行哦!

五个分别以不同的颜色表示如下

PackageTongXunLu;

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.*;

publicclassChangeDialogextendsJDialog{

TongxuluFrametongxuluFrame;

JTextFieldt1=newJTextField();

JTextFieldt2=newJTextField();

JTextFieldt3=newJTextField();

JTextFieldt4=newJTextField();

JTextFieldt5=newJTextField();

JTextFieldt6=newJTextField();

JButtonsave=newJButton("保存");

publicChangeDialog(TongxuluFrameframe,Strings,Booleanb){

super(frame,s,b);

this.tongxuluFrame=frame;

this.setSize(350,300);

this.setLocationRelativeTo(null);//设置窗口居中

this.setLayout(newGridLayout(7,2,20,10));

this.add(newJLabel("姓名:

",SwingConstants.CENTER));

this.add(t1);

this.add(newJLabel("年龄:

",SwingConstants.CENTER));

this.add(t2);

this.add(newJLabel("电话号码:

",SwingConstants.CENTER));

this.add(t3);

this.add(newJLabel("QQ:

",SwingConstants.CENTER));

this.add(t4);

this.add(newJLabel("邮箱:

",SwingConstants.CENTER));

this.add(t5);

this.add(newJLabel("备注:

",SwingConstants.CENTER));

this.add(t6);

this.add(newJLabel());

this.add(save);

save.addActionListener(newActionListener(){//添加事件

publicvoidactionPerformed(ActionEvente){

intselectedRow=tongxuluFrame.table.getSelectedRow();//获得选中行的索引

tongxuluFrame.tableModel.setValueAt(t1.getText(),selectedRow,0);

tongxuluFrame.tableModel.setValueAt(t2.getText(),selectedRow,1);

tongxuluFrame.tableModel.setValueAt(t3.getText(),selectedRow,2);

tongxuluFrame.tableModel.setValueAt(t4.getText(),selectedRow,3);

tongxuluFrame.tableModel.setValueAt(t5.getText(),selectedRow,4);

tongxuluFrame.tableModel.setValueAt(t6.getText(),selectedRow,5);

tongxuluFrame.m1.changeDialog.dispose();

}

});

}

}

packageTongXunLu;

importjava.awt.*;

importjavax.swing.*;

importjava.awt.event.*;

importjava.io.*;

publicclassFindDialogextendsJDialog{

TongxuluFrametongxuluFrame;

protectedJLabelnameLable=newJLabel("请输入姓名");

protectedJTextFieldfindInformation=newJTextField(10);

protectedJButtonfindButton=newJButton("查找");

protectedJButtoncancel=newJButton("取消");

FindMonitorfm=newFindMonitor();

ShowMessageDialogshowMessage;

publicFindDialog(TongxuluFrameframe,Strings,Booleanb){

super(frame,s,b);

this.tongxuluFrame=frame;

this.setSize(300,100);

this.setLocationRelativeTo(null);//设置窗口居中

this.setLayout(newGridLayout(2,2));

JPaneljp=newJPanel();

this.add(nameLable);

this.add(findInformation);

this.add(newJLabel());

this.add(jp);

jp.add(findButton);

findButton.addMouseListener(fm);

jp.add(cancel);

cancel.addMouseListener(newMouseAdapter(){

publicvoidmousePressed(MouseEvente){

tongxuluFrame.m1.findDialog.dispose();

}

});

}

classFindMonitorextendsMouseAdapter{

publicvoidmousePressed(MouseEvente){

intflag=0;//是否查到

System.out.println("成功");

try{

RandomAccessFilein=newRandomAccessFile(tongxuluFrame.f,"r");//文件读取

Strings=null;

Stringf=newString(findInformation.getText());//构造比较字符串

while((s=in.readUTF())!

=null){//循环查找

if(f.equals(s)){//本次循环查到了

showMessage=newShowMessageDialog(tongxuluFrame,f,true);

showMessage.setTitle(f+"的个人信息");

showMessage.l1.setText("姓名:

"+f);

showMessage.l3.setText("年龄:

"+in.readUTF());

showMessage.l5.setText("电话号码:

"+in.readUTF());

showMessage.l7.setText("QQ:

"+in.readUTF());

showMessage.l9.setText("邮箱:

"+in.readUTF());

showMessage.l11.setText("备注:

"+in.readUTF());

showMessage.setVisible(true);

flag=1;

}else{//本次循环没查到

in.readUTF();//读取email

in.readUTF();

in.readUTF();

in.readUTF();

in.readUTF();//读取tongxulu

}

}

if(flag==0){

JOptionPane.showMessageDialog(null,"没有查找到",

"Warnnig",JOptionPane.WARNING_MESSAGE);

}

in.close();//关闭文件

}catch(IOExceptionee){

}

}

}

PublicclassShowMessageDialogextendsJDialog{

JLabell1=newJLabel();

JLabell3=newJLabel();

JLabell5=newJLabel();

JLabell7=newJLabel();

JLabell9=newJLabel();

JLabell11=newJLabel();

JButtonconfirm=newJButton("确定");

publicShowMessageDialog(Framef,Strings,booleanb){

super(f,s,b);

Containerc=this.getContentPane();

this.setSize(200,300);

this.setLocationRelativeTo(null);//设置窗口居中

//this.setLayout(newGridLayout(6,1));

JPaneljp1=newJPanel();

jp1.setLayout(newGridLayout(6,1));

jp1.add(l1);

jp1.add(l3);

jp1.add(l5);

jp1.add(l7);

jp1.add(l9);

jp1.add(l11);

this.add(jp1,BorderLayout.CENTER);

JPaneljp2=newJPanel();

this.add(jp2,BorderLayout.SOUTH);

jp2.add(confirm);

confirm.setSize(200,500);

confirm.addMouseListener(newMouseAdapter(){

publicvoidmousePressed(MouseEvente){

tongxuluFrame.m1.findDialog.dispose();

tongxuluFrame.m1.findDialog.showMessage.dispose();

}

});

//confirm.setFont(newFont("SansSerif",Font.BOLD,15));

}

}

}

packageTongXunLu;

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.table.*;

importjava.io.*;

publicclassTongxuluFrameextendsJFrame{

protectedDefaultTableModeltableModel;//表格模型对象

protectedJTabletable;

String[]columnNames={"姓名","年龄","电话号码","QQ","邮箱","备注"};//列名

String[][]tableVales={};

JButtonaddInformation=newJButton("添加");

JButtonclear=newJButton("删除");

JButtonfind=newJButton("查找");

JButtonchange=newJButton("修改");

JButtonexit=newJButton("退出");

TongxuluMonitorm1;

JMenuBarmBar=newJMenuBar();//创建菜单条

JMenuselection=newJMenu("电话簿选项");

JMenusys=newJMenu("系统");//创建子菜单条

JMenuItemshow=newJMenuItem("修改联系人");

JMenuItemadd=newJMenuItem("增加联系人");

JMenuItemfind1=newJMenuItem("查找联系人");

JMenuItemdelete=newJMenuItem("删除联系人");

JMenuItemexit2=newJMenuItem("退出电话簿");

Filef=newFile("电话簿.txt");

publicTongxuluFrame(){

Containerc=this.getContentPane();

this.setTitle("TongXunLu");

this.setSize(700,250);

this.setLocationRelativeTo(null);//设置窗口居中

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

tableModel=newDefaultTableModel(tableVales,columnNames);

table=newJTable(tableModel);

table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

JScrollPanescrollPane=newJScrollPane(table);

c.add(scrollPane,BorderLayout.CENTER);

scrollPane.setViewportView(table);

try{

RandomAccessFilein=newRandomAccessFile(f,"r");

intcount=0;

Stringstr=null;

String[]string=newString[6];

str=in.readUTF();

while(true){

if(count==6){

String[]rowValues={string[0],string[1],string[2],string[3],string[4],string[5]};

tableModel.addRow(rowValues);

count=0;

}

string[count]=str;

count++;

if(str==null){

break;

}

str=in.readUTF();

}

in.close();

}catch(Exceptione){

//e.printStackTrace();

}

m1=newTongxuluMonitor(this);

selection.add(show);

show.addMouseListener(m1);

selection.add(add);

add.addMouseListener(m1);

selection.add(find1);

find1.addMouseListener(m1);

selection.add(delete);

delete.addActionListener(newActionListener(){//添加事件

publicvoidactionPerformed(ActionEvente){

intselectedRow=table.getSelectedRow();//获得选中行的索引

if(selectedRow!

=-1)//存在选中行

{

tableModel.removeRow(selectedRow);//删除行

}else{

JOptionPane.showMessageDialog(null,"请选中要删除对象",

"Warnnig",JOptionPane.WARNING_MESSAGE);

}

}

});

sys.add(exit2);

exit2.addMouseListener(m1);

mBar.add(selection);

mBar.add(sys);

this.setJMenuBar(mBar);

JPaneljp=newJPanel();

jp.add(addInformation);

addInformation.setFont(newFont("SansSerif",Font.BOLD,25));

jp.add(change);

change.setFont(newFont("SansSerif",Font.BOLD,25));

jp.add(find);

find.setFont(newFont("SansSerif",Font.BOLD,25));

jp.add(clear);

clear.setFont(newFont("SansSerif",Font.BOLD,25));

jp.add(exit);

exit.setFont(newFont("SansSerif",Font.BOLD,25));

c.add(jp,BorderLayout.SOUTH);

addInformation.addMouseListener(m1);

change.addMouseListener(m1);

find.addMouseListener(m1);

clear.addActionListener(newActionListener(){//添加事件

publicvoidactionPerformed(ActionEvente){

intselectedRow=table.getSelectedRow();//获得选中行的索引

if(selectedRow!

=-1)//存在选中行

{

tableModel.removeRow(selectedRow);//删除行

}else{

JOptionPane.showMessageDialog(null,"请选中要删除对象",

"Warnnig",JOptionPane.WARNING_MESSAGE);

}

}

});

exit.addMouseListener(m1);

}

publicstaticvoidmain(String[]args){

TongxuluFrameframe=newTongxuluFrame();

frame.setVisible(true);

}

}

packageTongXunLu;

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

importjava.io.*;

importjava.io.RandomAccessFile;

publicclassTongxuluJDialogextendsJDialog{

TongxuluFrametongxuluFrame;

finalstaticStringstring="";

TextFieldt1=newTextField();

JTextFieldt2=newJTextField();

JTextFieldt3=newJTextField();

JTextFieldt4=newJTextField();

JTextFieldt5=newJTextField();

JTextFieldt6=newJTextField();

JButtonsave=newJButton("保存");

JButtonexit=newJButton("取消");

JPaneljp=newJPanel();

publicTongxuluJDialog(TongxuluFrameframe,Strings,Booleanb){

super(frame,s,b);

this.tongxuluFrame=frame;

this.setSize(350,300);

this.setLocationRelativeTo(null);//设置窗口居中

this.setLayout(newGridLayout(7,2,20,10));

this.add(newJLabel("姓名:

",SwingConstants.CENTER));

this.add(t1);

this.add(newJLabel("年龄:

",SwingConstants.CENTER));

this.add(t2);

this.add(newJLabel("电话号码:

",SwingConstants.CENTER));

this.add(t3);

this.add(newJLabel("QQ:

",SwingConstants.CENTER));

this.add(t4);

this.add(newJLabel("邮箱:

",SwingConstants.CENTER));

this.add(t5);

this.add(newJLabel("备注:

",SwingConstants.CENTER));

this.add(t6);

this.add(newJLabel());

this.add(jp);

jp.add(save);

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2