个人通讯录JAVA代码完整版

本文分享了一段完整的JAVA代码,用于实现个人通讯录功能。通过这段代码,读者可以了解如何使用JAVA进行数据存储和检索,掌握基本的类设计和文件操作技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import java.awt.Choice;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.Printable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class MyAddBook {
	public static JFrame frame;
	public MyAddBook(){
		frame=new JFrame("个人通讯录");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		JMenuBar menubar=new JMenuBar();
		JMenu edit=new JMenu("编辑");
		JMenuItem edit1=new JMenuItem("录入");
		JMenuItem edit2=new JMenuItem("查询");
		JMenuItem edit3=new JMenuItem("删除");
		JMenuItem edit4=new JMenuItem("修改");
		JMenuItem edit5=new JMenuItem("排序");
		edit1.addActionListener(new Typein());
		JMenu show=new JMenu("显示信息");
		JMenuItem show1=new JMenuItem("同学");
		JMenuItem show2=new JMenuItem("同事");
		JMenuItem show3=new JMenuItem("朋友");
		JMenuItem show4=new JMenuItem("亲戚");
		JMenuItem show5=new JMenuItem("全体人员");
		Container c=frame.getContentPane();
		JPanel pane=new JPanel();
		c.add(pane);
		pane.add(menubar);
		menubar.add(edit);
		edit.add(edit1);
		edit.add(edit2);
		edit.add(edit3);
		edit.add(edit4);
		edit.add(edit5);
		menubar.add(show);
		show.add(show1);
		show.add(show2);
		show.add(show3);
		show.add(show4);
		show.add(show5);
		frame.setSize(300,100);
		//frame.pack();
		//查询修改删除
		class Search{
			JDialog dialog=new JDialog(frame,"查询对话框",true);
			public Search(String str,int n){
				dialog.setSize(250,200);
				Container c=dialog.getContentPane();
				dialog.setLayout(new GridLayout(2,1,5,5));
				JLabel Lsearch=new JLabel("请输入要"+str+"人员的名字:");
				final JTextField Tname=new JTextField(10);
				JButton certain=new JButton("确定");
				JButton cancel=new JButton("取消");
				//final String in=Tname.getText();
				JPanel pane1=new JPanel();
				JPanel pane2=new JPanel();
				c.add(pane1);
				c.add(pane2);
				pane1.add(Lsearch);
				pane1.add(Tname);
				pane2.add(certain);
				pane2.add(cancel);
				dialog.setDefaultCloseOperation(dialog.DISPOSE_ON_CLOSE);
				//dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
				if(n==2){
				  certain.addActionListener(new ActionListener()                            //查询
					{
						public void actionPerformed(ActionEvent e)                  
						{
							try {
								FileReader file=new FileReader("D:\\AddressBook.txt");
								Scanner find=new Scanner(file);
								while(find.hasNext()){
								if(find.next().equals(Tname.getText())){
									dialog.dispose(); 
									Typein fd=new Typein();
									fd.frame=new JFrame("查询结果如下");
									fd.Tname.setText(Tname.getText());
									fd.Cgroup.select(find.next());
									fd.Cbirthyear.select(find.next());
									fd.Cbirthmonth.select(find.next());
									fd.Cbirthday.select(find.next());
									fd.Tphone.setText(find.next());
									fd.Temail.setText(find.next());
									fd.Tother.setText(find.next());
									fd.typein();
									
								}
								}
								file.close();
								find.close();
							} catch (FileNotFoundException e1) {
								// TODO Auto-generated catch block
								//e1.printStackTrace();
								System.out.print("未找到文件");
							} catch (IOException e2) {
								// TODO Auto-generated catch block
								//e2.printStackTrace();
								System.out.print("未找到该人员");
							} 
						}
	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码奇才.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值