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("未找到该人员");
}
}