博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java通讯录
阅读量:5320 次
发布时间:2019-06-14

本文共 26252 字,大约阅读时间需要 87 分钟。

1设一个通信录由以下几项数据信息构成:

 

          数据项               类型

         姓名                  字符串

         地址                  字符串

         邮政编码              字符串

          电话号码             字符串

 

21.主要功能:

(1) 能建立、查询、修改和增删学生通讯录

(2) 能够按多种方式进行查询

3界面友好,易于操作

 

通讯录管理系统的设计与实现 

                             学生姓名:  指导老师:文斌

 

【中文摘要】  这个基于java编写的个人通讯录管理系统含有添加、删除、查找等基本功能,采用的是JDBC-ODBC桥实现数据库的连接,ODBC数据源名称chengwz.mbd。本课程设计主要解决通讯录应用的管理问题, 设计开发一个简单的通讯录系统 ,实现新建联系人,不同方式查找信息,删除信息,修改信息,联系人头像,退出系统等功能。在课程设计中,程序通过调试运行,初步实现了设计目标,并且经过适当完善后,将可以应用在通讯录应用的管理中,解决实际问题。用户和密码是123和123,系统所用的图片,自己用Photoshop制作的

 

关键词 :通讯录、java、通讯录应用、个人通讯录管理系统、添加、删除、查找,数据库。

效果图:::::::::::::::::::::::::::::::::::::::::::::::::

   

完整源代码:

//myframe.java

packagekkh;

 

importjava.awt.*;

importjava.awt.Event.*;

importjava.awt.event .*;

 

importjavax.swing.*;

importjavax.swing.event.*;

 

importjava.sql.*;

importjava.util.*;

 

 

publicclass myframe extends JFrame implements ActionListener,MouseListener{

JList lt;

privateJMenuBar mb;

privateJMenu mu1,mu2,mu3,mu4;

privateJMenuItem mi1,mi2,mi3,mi4,mi5,mi6,mi7;

DefaultListModeldm=new DefaultListModel();

JLabellb=new JLabel("业精于勤荒于嬉,行成于思毁于随!");

 

publicint j = 0;

publicint m = 0;

publicint t = 0;

publicint d=0,f=0,h=0,cag=0,del=0;

 

Stringstr1[] = new String[20]; // 姓名

Stringstr2[] = new String[20]; // 电话

Stringstr3[] = new String[20]; // QQ

Stringstr4[] = new String[20]; // 地址

Stringstr5[] = new String[20]; // 邮编

 

// 中间面板

classmypan extends JPanel implements ActionListener{  

        JLabel Name, Tel, QQq, Address,youb,lb2,lb3,lb4,lb5,lb6;

              JButton btn1, btn2,btn3;

 

       mypan(int index) {

              int x=index;

             

              setLayout(null);

              setBackground(Color.white);

             

 

                     Name = newJLabel(str1[x]+" 的联系方式");

                     Tel  = new JLabel("电话:");     lb2=new JLabel(str2[x]);

                     QQq   = new JLabel("QQ:");      lb3=new JLabel(str3[x]);

                     Address = new JLabel("地址:");  lb4=new JLabel(str4[x]);

                     youb=newJLabel("邮编");         lb5=new JLabel(str5[x]);

                     ImageIcon img6 = newImageIcon("D:\\workspace\\image\\2.jpg");

                     if(x==1)img6 = newImageIcon("D:\\workspace\\image\\3.jpg");

                 if(x==2)img6 = new ImageIcon("D:\\workspace\\image\\4.jpg");

                 if(x==3)img6=new ImageIcon("D:\\workspace\\image\\5.jpg");

                 if(x==4)img6 = new ImageIcon("D:\\workspace\\image\\6.jpg");

                 if(x==5)img6 = new ImageIcon("D:\\workspace\\image\\7.jpg");

                 if(x==6)img6 = new ImageIcon("D:\\workspace\\image\\8.jpg");

                 if(x==7)img6 = new ImageIcon("D:\\workspace\\image\\8.jpg");

                 if(x==8)img6 = new ImageIcon("D:\\workspace\\image\\9.jpg");

                 if(x==9)img6 = new ImageIcon("D:\\workspace\\image\\10.jpg");

                 

                 lb6=new JLabel("",img6,SwingConstants.LEADING);

 

                     btn1 = new JButton("删除");

                     btn2 = new JButton("退出");

                     btn3 = new JButton("修改");

                    

                     Name.   setBounds(340, 30, 200,30);Name.setForeground(Color.blue);

                     Tel.    setBounds(330, 80, 60, 30);

                     QQq.     setBounds(330, 130, 60, 30);

                     Address.setBounds(330, 180,60, 30);

                     youb.setBounds(330, 230,60, 30);

                    

                    

                     lb2.setBounds(370, 80, 180,30);    lb2.setForeground(Color.red);

                     lb3.setBounds(370, 130,180, 30);   lb3.setForeground(Color.red);

                     lb4.setBounds(370, 180, 180,30);   lb4.setForeground(Color.red);

              lb5.setBounds(370, 230, 180, 30);  lb5.setForeground(Color.red);

                     lb6.setBounds(100, 50, 200,200);

              

                     btn1.setBounds(250, 300,60, 30);

                     btn2.setBounds(350, 300,60, 30);

                     btn3.setBounds(150, 300,60, 30);

                    

                     this.add(btn1);

                     this.add(btn2);

                     this.add(btn3);

                     this.add(Name);

                     this.add(Tel);

                     this.add(QQq);

                     this.add(Address);

                     this.add(youb);

                     this.add(lb2);

                     this.add(lb3);

                     this.add(lb4);

                     this.add(lb5);

                     this.add(lb6);

                    

                 btn1.addActionListener(this);

                     btn2.addActionListener(this);

                     btn3.addActionListener(this);

       }

 

       /*public void paint(Graphics g) {

 

              super.paint(g);

              ImageIcon img = newImageIcon("D:\\1.jpg");

              g.drawImage(img.getImage(), 200,100, 800, 300, this);

       }*/

 

       @Override

       public void actionPerformed(ActionEvente) {

 

              // TODO 自动生成的方法存根

              if(e.getSource()==btn1){

                     try {

                           

                            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序

                           

                            String url ="jdbc:odbc:chengwz";// URL指向要访问的数据库名test

                            String user ="";// MySQL配置时的用户名

                            String password ="";// MySQL配置时的密码

                           

                            ResultSet rs=null ;

                            Connectionconnection = DriverManager.getConnection(url, user,password);// 连续数据库

                            if(!connection.isClosed())

                                   System.out.println("Succeededconnecting to the Database!");

                           

                            Statement statement= connection.createStatement();// statement用来执行SQL语句

                           

                            PreparedStatementpre=null;

                   String str2=str1[f];

                            Stringsq2="delete * from cwz where name=?";

             

                            pre=connection.prepareStatement(sq2);                          //要执行的SQL

                            pre.setString(1,str2);

                            pre.executeUpdate();

                                  

 

                         pre.close();

                            connection.close();

                     } catch (Exception ee) {

                            ee.printStackTrace();

                            System.out.println("============删除时:抛出异常===========");

                     }

                     dm.removeElementAt(f);

                     for (int d = f; d < j;d++) {

                     str1[d] = str1[d + 1];

                     str2[d] = str2[d + 1];

                     str3[d] = str3[d + 1];

                     str4[d] = str4[d + 1];

                     str5[d] = str5[d + 1];

              }

              j--;

              f--;

             

             

                       JOptionPane.showMessageDialog(null, "数据删除成功!");

                     }

               else if(e.getSource()==btn2){

                       dispose();

                       System.exit(0);

                     }

               else if(e.getSource()==btn3){

                      

                      new Revisefriend(f);

                     }

       }

}

 

/*-----------------------------------------------------------------------------*/

mypanpn2=new mypan(f);mypan pnc=new mypan(f);

JLabelName, Tel, QQq, Address, youb,lb2,lb3,lb4,lb5,lb6;

JButtonbtn1, btn2,btn3;

publicmyframe(){

try {

             

              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序

             

              String url ="jdbc:odbc:chengwz";// URL指向要访问的数据库名test

              String user = "";//MySQL配置时的用户名

              String password = "";//MySQL配置时的密码

              Connection connection =DriverManager.getConnection(url, user, password);// 连续数据库

              if(!connection.isClosed())

                     System.out.println("Succeededconnecting to the Database!");

             

              Statement statement =connection.createStatement();// statement用来执行SQL语句

              String sql = "select * fromcwz";// 要执行的SQL语句

              ResultSet rs =statement.executeQuery(sql);// 执行SQL语句并返回结果集

             

              String name = null;

              Stringphone=null;

              String QQ=null;

              String youbian=null;

              String address=null;

             

              while(rs.next()) {

                    

                     name =rs.getString("name");// 选择sname这列数据

                     phone=rs.getString("phone");

                     QQ=rs.getString("QQ");

                     address=rs.getString("address");

                     youbian=rs.getString("postcard");

                    

                     str1[j] = name;

                     str2[j] = phone;

                     str3[j] =QQ;

                     str4[j] = address;

                     str5[j] = youbian;

                     j++;

                     dm.addElement(name+"     "+phone+"     "+address);

              }

              rs.close();// 关闭结果集

              connection.close();// 关闭连接

       } catch(ClassNotFoundException e) {

              System.out.println("Sorry,can`tfind the Driver!");

              e.printStackTrace();

       } catch(SQLException e) {

              e.printStackTrace();

       } catch(Exception e) {

              e.printStackTrace();

       }

      

 

       JPanel pn=new JPanel();  JPanel pn3=new JPanel();

       mypan pn2=new mypan(f);

       mb=new JMenuBar();

       mu1=new JMenu("好友操作"); mi1=new JMenuItem("修改");mi2=new JMenuItem("删除");

       mu2=new JMenu("查询");   mi3=new JMenuItem("按姓名");mi4=newJMenuItem("按电话");

       mu3=new JMenu("新增");   mi5=new JMenuItem("新建联系人");

       mu4=new JMenu("帮助");   mi6=new JMenuItem("关于");mi7=newJMenuItem("退出系统");

      

       setJMenuBar(mb);

       mb.add(mu1);mu1.add(mi1);mu1.add(mi2);

       mb.add(mu2);mu2.add(mi3);mu2.add(mi4);

       mb.add(mu3);mu3.add(mi5);

       mb.add(mu4);mu4.add(mi6);mu4.add(mi7);

    lb.setForeground(Color.black );

       pn.add(lb);

      

       lt=new JList(dm);

       lt.setSelectionForeground(Color.blue); //选中后的字体颜色

       lt.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

       JScrollPane sp=new JScrollPane(lt);

      

      

       

        ImageIcon icon=newImageIcon("D:\\1.jpg");

        JLabel lbn=new JLabel("8",icon,SwingConstants.LEADING);

        pn3.add(lbn);

       

       add(sp,"West");

       add(pn,"South");

       add(pn2,"Center");

       add(pn3,"North");

      

       mi1.addActionListener(this);

       mi2.addActionListener(this);

       mi3.addActionListener(this);

       mi4.addActionListener(this);

       mi5.addActionListener(this);

       mi6.addActionListener(this);

       mi7.addActionListener(this);

    lt.addMouseListener(this);

 

      

       setSize(800,570);

       setTitle("通讯录 1.1");

       setVisible(true);

       setResizable(false);//缩放

       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       setLocationRelativeTo(null);

       JFrame.setDefaultLookAndFeelDecorated(true);

       /*Font font=newFont("JFrame",Font.PLAIN,14);

       Enumeration keys=UIManager.getLookAndFeelDefaults().keys();

       while(keys.hasMoreElements()){

              Object key=keys.nextElement();

              if(UIManager.get(key)instanceofFont)UIManager.put(keys, font);

       }*/

      

      

}

publicvoid actionPerformed(ActionEvent e){

  if(e.getSource()==mi1){

              new ReviseFriendname();

       }

       else if(e.getSource()==mi2){

       new Deletefriend();

       }

       else if(e.getSource()==mi3){

              new Searchfriend();

       }

       else if(e.getSource()==mi4){

         new search2();

       }

       else if(e.getSource()==mi5){

              new Addfriend();

             

       }

       else if(e.getSource()==mi6){

             

              new about ();

 

       }

  else if(e.getSource()==mi7){

      this.dispose();

       }

 

}

@Override

publicvoid mouseClicked(MouseEvent e) {

       // TODO 自动生成的方法存根

       if (e.getClickCount() == 1)

         {

            int index=lt.locationToIndex(e.getPoint());

              f=index;      

               pn2.removeAll();

                    

                     System.out.println("balck");

                     Name = newJLabel(str1[index]+" 的联系方式");

                     Tel  = new JLabel("电话:");     lb2=new JLabel(str2[index]);

                     QQq   = new JLabel("QQ:");      lb3=new JLabel(str3[index]);

                     Address= new JLabel("地址:");   lb4=new JLabel(str4[index]);

                     youb=new JLabel("邮编");         lb5=new JLabel(str5[index]);

                     ImageIcon img6 = newImageIcon("D:\\workspace\\image\\2.jpg");

                     if(index==1)img6 = newImageIcon("D:\\workspace\\image\\3.jpg");

                 if(index==2)img6 = newImageIcon("D:\\workspace\\image\\4.jpg");

                 if(index==3)img6=new ImageIcon("D:\\workspace\\image\\5.jpg");

                 if(index==4)img6 = newImageIcon("D:\\workspace\\image\\6.jpg");

                 if(index==4)img6 = new ImageIcon("D:\\workspace\\image\\6.jpg");

                 if(index==5)img6 = newImageIcon("D:\\workspace\\image\\7.jpg");

                 if(index==6)img6 = newImageIcon("D:\\workspace\\image\\8.jpg");

                 if(index==7)img6 = newImageIcon("D:\\workspace\\image\\8.jpg");

                 if(index==8)img6 = newImageIcon("D:\\workspace\\image\\9.jpg");

                 if(index==9)img6 = newImageIcon("D:\\workspace\\image\\10.jpg");

                 lb6=new JLabel("",img6,SwingConstants.LEADING);

 

                     btn1 = new JButton("删除");

                     btn2 = new JButton("退出");

                     btn3 = new JButton("修改");

                    

                     Name.   setBounds(340, 30, 200,30);Name.setForeground(Color.blue);

                     Tel.    setBounds(330, 80, 60, 30);

                     QQq.     setBounds(330, 130, 60, 30);

                     Address.setBounds(330, 180,60, 30);

                     youb.setBounds(330, 230,60, 30);

                    

                    

                     lb2.setBounds(370,80, 180, 30);   lb2.setForeground(Color.red);

                     lb3.setBounds(370, 130,180, 30);   lb3.setForeground(Color.red);

                     lb4.setBounds(370, 180,180, 30);   lb4.setForeground(Color.red);

              lb5.setBounds(370, 230, 180, 30);  lb5.setForeground(Color.red);

                     lb6.setBounds(100, 50, 200,200);

              

                     btn1.setBounds(250, 300,60, 30);

                     btn2.setBounds(350, 300,60, 30);

                     btn3.setBounds(150, 300,60, 30);

                    

                     pn2.add(btn1);

                     pn2.add(btn2);

                     pn2.add(btn3);

                     pn2.add(Name);

                     pn2.add(Tel);

                     pn2.add(QQq);

                     pn2.add(Address);

                     pn2.add(youb);

                     pn2.add(lb2);

                     pn2.add(lb3);

                     pn2.add(lb4);

                     pn2.add(lb5);

                     pn2.add(lb6);

                    

                     add(pn2,"Center");

                     pn2.updateUI();

         }

       if (e.getClickCount() == 2)

         {

           int index=lt.locationToIndex(e.getPoint());

           new delete(index);

           

         }

}

@Override

publicvoid mouseEntered(MouseEvent e) {

       // TODO 自动生成的方法存根

      

}

@Override

publicvoid mouseExited(MouseEvent arg0) {

       // TODO 自动生成的方法存根

      

}

@Override

publicvoid mousePressed(MouseEvent e) {

       // TODO 自动生成的方法存根

      

}

@Override

publicvoid mouseReleased(MouseEvent arg0) {

       // TODO 自动生成的方法存根

      

}

 

//增加好友界面

              public   class Addfriend extends JFrame implementsActionListener {

 

                     JTextField uTxt1, uTxt2,uTxt3, uTxt4,yb;

                     JLabel Name, Tel, QQ,Address,youbian;

                     JButton btn1, btn2;

                     Addfriend() {

                            this.setSize(500,390);

                            this.setTitle("增加好友");

                            this.setLayout(null);

 

                            Name = newJLabel("姓名:");

                            Tel = newJLabel("电话:");

                            QQ = newJLabel("QQ:");

                            Address = newJLabel("地址:");

                            youbian=newJLabel("邮编");

                           

 

                            btn1 = newJButton("新增");

                            btn2 = newJButton("取消");

 

                            uTxt1 = newJTextField(20);

                            uTxt2 = newJTextField(20);

                            uTxt3 = newJTextField(20);

                            uTxt4 = newJTextField(20);

                            yb=newJTextField(20);

 

                            Name.setBounds(130,30, 60, 30);

                            Tel.setBounds(130,80, 60, 30);

                            QQ.setBounds(130,130, 60, 30);

                            Address.setBounds(130,180, 60, 30);

                            youbian.setBounds(130,230, 60, 30);

                           

                            uTxt1.setBounds(170,30, 180, 30);

                            uTxt2.setBounds(170,80, 180, 30);

                            uTxt3.setBounds(170,130, 180, 30);

                            uTxt4.setBounds(170,180, 180, 30);

                yb.setBounds(170, 230, 180, 30);

                           

                            btn1.setBounds(150,300, 60, 30);

                            btn2.setBounds(300,300, 60, 30);

 

                            this.add(btn1);

                            this.add(btn2);

 

                            this.add(Name);

                            this.add(Tel);

                            this.add(QQ);

                            this.add(Address);

                            this.add(youbian);

                    

                            this.add(uTxt1);

                            this.add(uTxt2);

                            this.add(uTxt3);

                            this.add(uTxt4);

                            this.add(yb);

 

                            btn1.addActionListener(this);

                            btn2.addActionListener(this);

                           

                            this.setLocation(650,340);

                            this.dispose();

                            this.setVisible(true);

                     }

                     public voidactionPerformed(ActionEvent e) {

                            if (e.getSource() ==btn1) {

                                   if(uTxt1.getText().trim().equals(""))newkong();

                                   else{

                                   str1[j] =uTxt1.getText();

                                   str2[j] =uTxt2.getText();

                                   str3[j] =uTxt3.getText();

                                   str4[j] =uTxt4.getText();

                                   str5[j] =yb.getText();

                                   j++;

                                   try {

                                         

                                          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序

                                          Stringurl = "jdbc:odbc:chengwz";            // URL指向要访问的数据库名test

                                          Stringuser = "";                            // MySQL配置时的用户名

                                          Stringpassword = "";                        // MySQL配置时的密码

                                          Connectionconnection = DriverManager.getConnection(url, user, password);// 连续数据库

                                         

                                          PreparedStatementpre=null;

                                         

                                          if(!connection.isClosed())

                                                 System.out.println("Succeededconnecting to the Database!");

                                         

                                          Statementstatement = connection.createStatement();             // statement用来执行SQL语句

                                         

                                          Stringsql = "insert into cwz(name,phone,QQ,address,postcard)values(?,?,?,?,?)";

                                         

                                          pre=connection.prepareStatement(sql);                           // 要执行的SQL语句

                                         

                                          pre.setString(1,uTxt1.getText());

                                          pre.setString(2,uTxt2.getText());

                                          pre.setString(3,uTxt3.getText());

                                          pre.setString(4,uTxt4.getText());

                                          pre.setString(5,yb.getText());

                                         

                                       pre.executeUpdate();                                             //执行

                                         

                                          dm.addElement(uTxt1.getText()+"     "+uTxt2.getText()+"     "+uTxt4.getText());

                                          pre.close();//关闭结果集

                                          connection.close();//关闭连接

                                         

                                   }catch(Exception ee) {

                                          System.out.println("==charucuowu");

                                          ee.printStackTrace();

                                   }

                                  

                                   this.dispose();}

                            }

                           

                            if (e.getSource() ==btn2) {

                                   this.dispose();

                            }

                     }                  

              }

//按姓名查询好友界面

              public class Searchfriend extendsJFrame implements ActionListener {

 

                     JLabel label;

                     JTextField uTxt;

                     JButton btn1, btn2;

                     int f=0;

 

                     Searchfriend() {

                            this.setSize(400,300);

                            this.setTitle("查询好友");

                            this.setLayout(null);

 

                            label = newJLabel("好友名");

                            uTxt = newJTextField(20);

                            btn1 = newJButton("查询");

                            btn2 = newJButton("退出");

 

                            label.setBounds(80,100, 60, 30);

                            uTxt.setBounds(130,100, 140, 30);

                            btn1.setBounds(100,200, 60, 30);

                            btn2.setBounds(220,200, 60, 30);

 

                            this.add(label);

                            this.add(uTxt);

                            this.add(btn1);

                            this.add(btn2);

                            btn1.addActionListener(this);

                            btn2.addActionListener(this);

                            this.setLocation(650,340);

                            this.dispose();

                            this.setVisible(true);

                     }

 

                     public voidactionPerformed(ActionEvent e) {

                            if (e.getSource() ==btn1) {

                                   if(uTxt.getText().trim().equals(""))

                                          JOptionPane.showMessageDialog(null,"请输入姓名 !");

                                          else{

                                   for (f = 0; f<= j; f++)

                                         

                                          if(uTxt.getText().equals(str1[f]))

                                                 newdelete(f);

                                          for(f=0;(f<=j)&&(!uTxt.getText().equals(str1[f]));f++)

                                                 if(!uTxt.getText().equals(str1[f])&&f==j)

                                                        JOptionPane.showMessageDialog(null,"通讯录中没有此联系人 !");

                                       this.dispose();

                                         

                                   }

                            }

                            if (e.getSource() ==btn2) {

                                   this.dispose();

                            }

 

                     }

              }

//按电话号码查询好友界面

                            public class search2extends JFrame implements ActionListener {

 

                                   JLabel label;

                                   JTextFielduTxt;

                                   JButton btn1,btn2;

 

                                   search2() {

                                          this.setSize(400,300);

                                          this.setTitle("查询好友");

                                          this.setLayout(null);

 

                                          label= new JLabel("电话");

                                          uTxt =new JTextField(20);

                                          btn1 =new JButton("查询");

                                          btn2 =new JButton("退出");

 

                                          label.setBounds(80,100, 60, 30);

                                          uTxt.setBounds(130,100, 140, 30);

                                          btn1.setBounds(100,200, 60, 30);

                                          btn2.setBounds(220,200, 60, 30);

 

                                          this.add(label);

                                          this.add(uTxt);

                                          this.add(btn1);

                                          this.add(btn2);

                                          btn1.addActionListener(this);

                                          btn2.addActionListener(this);

                                          this.setLocation(650,340);

                                          this.dispose();

                                          this.setVisible(true);

                                   }

 

                                   public voidactionPerformed(ActionEvent e) {

                                          if(e.getSource() == btn1) {

                                                

                                                 if(uTxt.getText().trim().equals(""))

                                                        JOptionPane.showMessageDialog(null,"请输入联系人号码!");

                                                        else{

                                                 for(f = 0; f <= j; f++)

                                                        if(uTxt.getText().equals(str2[f]))

                                                               newdelete(f);

                                                        for(f=0;(f<=j)&&(!uTxt.getText().equals(str2[f]));f++)

                                                        if((!uTxt.getText().equals(str2[f]))&&(f==j))

                                                        newnone();

                                                 this.dispose();}

                                          }

                                          if(e.getSource() == btn2) {

                                                 this.dispose();

                                          }

 

                                   }

                            }

 

 

//好友信息修改界面

              public class Revisefriend extendsJFrame implements ActionListener,

                            ItemListener {

 

                     JTextField uTxt1, uTxt2,uTxt3, uTxt4,yb;

                     JLabel Name, Tel, QQ,Address, youbian;

                     JButton btn1, btn2;

             

                     Revisefriend(int t) {

                            this.setSize(500,380);

                            this.setTitle("好友信息");

                            this.setLayout(null);

 

                            Name = newJLabel("姓名:");

                            Tel = newJLabel("电话:");

                            QQ = newJLabel("QQ:");

                            Address = newJLabel("地址:");

                            youbian=newJLabel("邮编");

                           

                            btn1 = newJButton("修改");

                            btn2 = newJButton("取消");

                           

                            uTxt1 = newJTextField(20);

                            uTxt2 = newJTextField(20);

                            uTxt3 = newJTextField(20);

                            uTxt4 = newJTextField(20);

                            yb=new JTextField(20);

 

                            Name.setBounds(130,30, 60, 30);

                            Tel.setBounds(130,80, 60, 30);

                            QQ.setBounds(130,130, 60, 30);

                            Address.setBounds(130,180, 60, 30);

                            youbian.setBounds(130,230, 60, 30);

                           

                            uTxt1.setBounds(170,30, 180, 30);

                            uTxt2.setBounds(170,80, 180, 30);

                            uTxt3.setBounds(170,130, 180, 30);

                            uTxt4.setBounds(170,180, 180, 30);

           yb.setBounds(170, 230, 180, 30);

                           

                            btn1.setBounds(150,290, 60, 30);

                            btn2.setBounds(320,290, 60, 30);

                           

                           

                            uTxt1.setText(str1[t]);

                            uTxt2.setText(str2[t]);

                            uTxt3.setText(str3[t]);

                            uTxt4.setText(str4[t]);

                            yb   .setText(str5[t]);

 

                            this.add(btn1);

                            this.add(btn2);

                            this.add(Name);

                            this.add(Tel);

                            this.add(QQ);

                            this.add(Address);

                            this.add(youbian);

                            this.add(uTxt1);

                            this.add(uTxt2);

                            this.add(uTxt3);

                            this.add(uTxt4);

                            this.add(yb);

 

                            btn1.addActionListener(this);

                            btn2.addActionListener(this);

                           

                            this.setLocation(650,340);

                            this.dispose();

                            this.setVisible(true);

 

                     }

 

                     public voidactionPerformed(ActionEvent e) {

                           

                                   if(e.getSource() == btn1) {

                                          t=cag;

                                          if(uTxt1.getText().trim().equals(""))newkong();

                                          else{

                                          str1[t]= uTxt1.getText();

                                          str2[t]= uTxt2.getText();

                                          str3[t]= uTxt3.getText();

                                          str4[t]= uTxt4.getText();                                                             

                                          str5[t]= yb.getText();

                                                 dm.removeElementAt(t);

                                   dm.add(t,uTxt1.getText()+"     "+uTxt2.getText()+"     "+uTxt4.getText());

                                  

                                   try {

                                          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序                      

                                          Stringurl = "jdbc:odbc:chengwz";

                                          Stringuser = "";

                                          Stringpassword = "";

                                          PreparedStatementpre=null;

                                          ResultSetrs;

                                          Connectionconnection = DriverManager.getConnection(url, user, password);

                                          if(!connection.isClosed())

                                                 System.out.println("Succeededconnecting to the Database!");

                                         

                                          Statementstatement = connection.createStatement();            // statement用来执行SQL语句

 

                                          Stringsql = "update cwz set name=?,phone=?,QQ=?,address=?,postcard=? wherename=?";

                                         

                                          pre=connection.prepareStatement(sql);                          //要执行的SQL

                           

                                          pre.setString(1,uTxt1.getText());

                                          pre.setString(2,uTxt2.getText());

                                          pre.setString(3,uTxt3.getText());

                                          pre.setString(4,uTxt4.getText());

                                          pre.setString(5,yb.getText());

                                          pre.setString(6,uTxt1.getText());

                                         

                                       pre.executeUpdate();

                           

                                          pre.close();//关闭结果集

                                          connection.close();//关闭连接

                                         

                                   }catch(Exception ee) {

                                          System.out.println("==修改时出错==");

                                          ee.printStackTrace();

                                   }

                                   this.dispose();

                                   }

 

                            }

                            else if(e.getSource() == btn2) {

 

                                   this.dispose();

                            }

                           

                     }

 

                     public voiditemStateChanged(ItemEvent e) {

 

                     }

              }

 

//修改好友提示界面

              public class ReviseFriendnameextends JFrame implements ActionListener {

 

                     JLabel FriendName;

                     JTextField uTxt;

                     JButton btn1, btn2;

                    

                     ReviseFriendname() {

                            this.setSize(400,300);

                            this.setTitle("修改好友");

                            this.setLayout(null);

 

                            FriendName = newJLabel("好友名");

                            uTxt = newJTextField(20);

                            btn1 = newJButton("搜索");

                            btn2 = newJButton("退出");

 

                            FriendName.setBounds(80,100, 60, 30);

                            uTxt.setBounds(140,100, 160, 30);

                            btn1.setBounds(100,200, 60, 30);

                            btn2.setBounds(220,200, 60, 30);

 

                            btn1.addActionListener(this);

                            btn2.addActionListener(this);

                            this.add(FriendName);

                            this.add(uTxt);

                            this.add(btn1);

                            this.add(btn2);

                           

 

                            this.setLocation(650,340);

                            this.dispose();

                            this.setVisible(true);

                     }

 

                     public voidactionPerformed(ActionEvent e) {

        

            if (e.getSource() == btn1) {

              if(uTxt.getText().trim().equals(""))newkong();

                                   else{

                                   for (m = 0;m<=j; m++)

                                     if (uTxt.getText().equals(str1[m])){

                                            cag=m;

                                            new Revisefriend(m);

                                            }

                                   for (m = 0;m<=j&&!(uTxt.getText().equals(str1[m])); m++)

                                    if((!(uTxt.getText().equals(str1[m])))&&(m==j))

                                                        newnone();

                                   this.dispose();

                                   }

                            }

                            if (e.getSource() ==btn2) {

                                   this.dispose();

 

                            }

                     }

              }

 

//删除好友界面1

              public class Deletefriend extendsJFrame implements ActionListener {

                     JLabel FriendName;

                     JTextField uTxt;

                     JButton btn1, btn2;

                    

                     String name;

                    

 

                     Deletefriend() {

                            this.setSize(400, 300);

                            this.setTitle("搜索你要删除的好友名  ");

                            this.setLayout(null);

 

                            FriendName = newJLabel("好友名");                      

                         uTxt = new JTextField(20);

                            btn1 = newJButton("打开");

                            btn2 = newJButton("退出");

 

                            FriendName.setBounds(80,60, 100, 30);

                            uTxt.setBounds(140,60, 180, 30);

                           

                            btn1.setBounds(100,200, 60, 30);

                            btn2.setBounds(200,200, 60, 30);

 

                            this.add(uTxt);

                            this.add(FriendName);

                           

                            this.add(btn1);

                            this.add(btn2);

 

                            btn1.addActionListener(this);

                            btn2.addActionListener(this);

                           

                            this.setLocation(650,340);

                            this.dispose();

                            this.setVisible(true);

                     }

 

                     public voidactionPerformed(ActionEvent e) {

 

                            if (e.getSource() ==btn2) {

                                   this.dispose();

                            }

                            if (e.getSource() ==btn1) {

                                   if(uTxt.getText().trim().equals(""))newkong();

                                   else{

                                   for (int h =0; h <= j; h++)

                                          if(uTxt.getText().equals(str1[h])) {

                                                

                                                 newdelete(h);

                                                

                                                

                                          }

                                          for(inth1=0;h1<=j&&(!uTxt.getText().equals(str1[h1]));h1++)

                                          if((!uTxt.getText().equals(str1[h1])&&h1==j))

                                                        newnone();

                                  

                                   this.dispose();}

                            }

                     }

              }

//删除好友界面2

              public class delete extends JFrameimplements ActionListener {

       JLabel Name, Tel, QQq, Address,youb,lb2,lb3,lb4,lb5;

       JButton btn1, btn2;

       delete(int h) {

              f=h;

              this.setSize(500, 380);

              this.setTitle("联系人信息");

              this.setLayout(null);

              Name = new JLabel(str1[f]+" 的联系方式");

              Tel  = new JLabel("电话:");   lb2=new JLabel(str2[f]);

              QQq   = new JLabel("QQ:");     lb3=new JLabel(str3[f]);

              Address = new JLabel("地址:"); lb4=new JLabel(str4[f]);

              youb=new JLabel("邮编");   lb5=new JLabel(str5[f]);

 

              btn1 = new JButton("删除");

              btn2 = new JButton("返回");

             

              Name.   setBounds(190, 30, 200,30);Name.setForeground(Color.blue);

              Tel.    setBounds(180, 80, 60, 30);

              QQq.     setBounds(180, 130, 60, 30);

              Address.setBounds(180, 180, 60,30);

              youb.setBounds(180, 230, 60, 30);

             

             

              lb2.setBounds(220, 80, 180,30);    lb2.setForeground(Color.red);

              lb3.setBounds(220, 130, 180,30);   lb3.setForeground(Color.red);

              lb4.setBounds(220, 180, 180,30);   lb4.setForeground(Color.red);

   lb5.setBounds(220, 230, 180, 30);   lb5.setForeground(Color.red);

             

              btn1.setBounds(150, 270, 60, 30);

              btn2.setBounds(300, 270, 60, 30);

             

              this.add(btn1);

              this.add(btn2);

              this.add(Name);

              this.add(Tel);

              this.add(QQq);

              this.add(Address);

              this.add(youb);

              this.add(lb2);

              this.add(lb3);

              this.add(lb4);

              this.add(lb5);

 

              btn1.addActionListener(this);

              btn2.addActionListener(this);

             

              this.setLocation(650,340);

              this.dispose();

              this.setVisible(true);

             

       }

      

       public void actionPerformed(ActionEvente) {                 

                     if (e.getSource() == btn1){

                            try {

                                  

                                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序

                                  

                                   String url ="jdbc:odbc:chengwz";// URL指向要访问的数据库名test

                                   String user ="";// MySQL配置时的用户名

                                   Stringpassword = "";// MySQL配置时的密码

                                  

                                   ResultSetrs=null ;

                                   Connectionconnection = DriverManager.getConnection(url, user,password);// 连续数据库

                                   if(!connection.isClosed())

                                          System.out.println("Succeededconnecting to the Database!");

                                  

                                   Statementstatement = connection.createStatement();// statement用来执行SQL语句

                                  

                                   PreparedStatementpre=null;

                          String str2=str1[f];

                                   Stringsq2="delete * from cwz where name=?";

                    

                                   pre=connection.prepareStatement(sq2);                          //要执行的SQL

                                   pre.setString(1,str2);

                                   pre.executeUpdate();

                                         

 

                                pre.close();

                                   connection.close();

                            } catch (Exceptionee) {

                                   ee.printStackTrace();

                                   System.out.println("============删除时:抛出异常===========");

                            }

                            dm.removeElementAt(f);

                            for (int d = f; d< j; d++) {

                            str1[d] = str1[d +1];

                            str2[d] = str2[d +1];

                            str3[d] = str3[d +1];

                            str4[d] = str4[d +1];

                            str5[d] = str5[d +1];

                     }

                     j--;

                     f--;

                    

                            this.dispose();

              }

              else if (e.getSource() == btn2) {

 

                     this.dispose();

              }

       }

}

//关于

              public class about extends JFrame{

       JLabel lb1, lb2,lb3,lb4,lb5;

      

 

       about() {

              this.setSize(300, 200);

              this.setTitle("关于");

              this.setLayout(null);

 

              lb1 = new JLabel("               java 课程设计    通讯录  1.1");

              lb2 = new JLabel("海南师范大学信息学院  2012级计本(1)班   ");

   lb3 = new JLabel("                                  指导老师:文   斌 ");

   lb4 = new JLabel("                                       2013.12");

              lb5 = new JLabel("陈万洲 201224010203");

              lb1.setBounds(20, 0, 400, 50);

              lb2.setBounds(20, 20, 400, 50);

              lb5.setBounds(20, 40, 400, 50);

              lb3.setBounds(20, 60, 400, 100);

              lb4.setBounds(20, 80, 400, 100);

             

              lb1.setForeground(Color.blue);

             

              this.add(lb1);

              this.add(lb2);

              this.add(lb3);

              this.add(lb4);

              this.add(lb5);

             

              this.setLocation(650,340);

              this.dispose();

              this.setVisible(true);

 

       }

}

//查无此人

              public class none extends JFrame {

       JLabel lb1;

       none() {

              this.setSize(300, 200);

              this.setTitle("提示");

              this.setLayout(null);

 

              lb1 = new JLabel("查无此联系人!");

             

              lb1.setBounds(20, 0, 400, 100);

              lb1.setForeground(Color.RED);

             

              this.add(lb1);

             

             

              this.setLocation(650,340);

              this.dispose();

              this.setVisible(true);

 

       }

      

}

              //没有输入名字提示界面

              public class kong extends JFrameimplements ActionListener{

                     JLabel lb1;

                     JButton bt=newJButton("OK");

                     kong() {

                            this.setSize(300,200);

                            this.setTitle("提示");

                            this.setLayout(null);

 

                            lb1 = newJLabel("请输入好友姓名 !");

                           

                            lb1.setBounds(20, 0,400, 100);

                            bt.setBounds(120,100, 60, 30);

                            lb1.setForeground(Color.blue);

                            bt.setForeground(Color.blue);

                            this.add(lb1);

                            this.add(bt);

                            bt.addActionListener(this);

                           

                            this.setLocation(1019,414);

                            this.dispose();

                            this.setVisible(true);

 

                     }

                     @Override

                     public voidactionPerformed(ActionEvent e) {

                            // TODO 自动生成的方法存根

                            dispose();

                     }

                    

              }

              }

 

//enter.java     登录界面

packagekkh;

 

importjava.awt.event.*;

importjava.awt.*;

 

importjavax.swing.*;

 

 class enter extends JFrame implementsActionListener {

 

       JLabel lb,user,mima;

       JButton btn;

    JProgressBar pg=new JProgressBar(1, 100);

   Timer tim;

  public JTextField user2;

   public JPasswordField mima2;

  

   int n=100;

  

       enter() {

              setSize(550, 420);

              //setTitle("系统登录");

             

              pg.setStringPainted(true);

              pg.setString("沟通、从这里开始!");

              pg.setBackground(Color.white);

              pg.setForeground(Color.yellow);

              toFront();

              tim=new javax.swing.Timer(100, this);

              tim.addActionListener(this);

             

             

              JPanel pn=new JPanel();

              setContentPane(pn);

              pn.setLayout(null);

             

              user2=new JTextField(6);

              mima2=new JPasswordField(6);

              mima2.setEchoChar('*');

              user=new JLabel("用户:");

              mima=new JLabel("密码:");

              ImageIcon img3= newImageIcon("D:\\workspace\\image\\23.jpg");

              lb=new JLabel(img3);

             

              ImageIcon img1= newImageIcon("D:\\workspace\\image\\enter.jpg");

              btn = new JButton(img1);

             

              user.setBounds(20, 150, 50,30);user2.setBounds(55, 150, 100, 30);

              mima.setBounds(20,200, 50, 30);mima2.setBounds(55, 200, 100, 30);

              pg.setBounds(0, 346, 550, 30);

              lb.setBounds(0, 0, 550, 358);

              btn.setBounds(240, 249, 76, 41);

              btn.setEnabled(true);

             

              pn.add(user);pn.add(user2);

              pn.add(mima);pn.add(mima2);

              pn.add(pg);

              pn.add(btn);

              pn.add(lb);

             

             

              btn.addActionListener(this);

             

              this.setLocationRelativeTo(null);

              this.dispose();

              this.setVisible(true);

       }

 

       public void actionPerformed(ActionEvente) {

              if (e.getSource() == btn) {

                     if(user2.getText().trim().equals("123")&&(mima2.getText().trim().equals("123"))){

                     tim.start();

                     pg.setString("正在进入通讯录系统.......");

                     setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                     }

                     elseJOptionPane.showMessageDialog(null, "你输入的账号和密码不匹配!");

                     }

              else if(--n>0){

                     pg.setValue(100-n);

                     tim.restart();

              }

       else{

                     tim.stop();

                     dispose();

                     JFrame.setDefaultLookAndFeelDecorated(true);

                     myframe fr=new myframe();

              }

             

      

       }

 

       }

 

//dome.java 程序入口mian()

packagekkh;

 

importjavax.swing.*;

 

 

publicclass dome {

 

       public static void main(String[] args) {

              // TODO 自动生成的方法存根

                            JFrame.setDefaultLookAndFeelDecorated(true);

        enter et=new enter();

       }

 

}

转载于:https://www.cnblogs.com/oversea201405/p/3752066.html

你可能感兴趣的文章
大数据学习
查看>>
简单工厂模式
查看>>
Delphi7编译的程序自动中Win32.Induc.a病毒的解决办法
查看>>
Objective-C 【关于导入类(@class 和 #import的区别)】
查看>>
倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-点击运行按钮进入到运行状态报错Error starting TwinCAT System怎么办 AdsWarning1823怎么办...
查看>>
【转】javascript 中的很多有用的东西
查看>>
Centos7.2正常启动关闭CDH5.16.1
查看>>
Android 监听返回键、HOME键
查看>>
Android ContentProvider的实现
查看>>
sqlserver 各种判断是否存在(表名、函数、存储过程等)
查看>>
给C#学习者的建议 - CLR Via C# 读后感
查看>>
Recover Binary Search Tree
查看>>
Java 实践:生产者与消费者
查看>>
[转]IOCP--Socket IO模型终结篇
查看>>
js 获取视频的第一帧
查看>>
各种正则验证
查看>>
观察者模式(Observer)
查看>>
python中numpy.r_和numpy.c_
查看>>
egret3D与2D混合开发,画布尺寸不一致的问题
查看>>
freebsd 实现 tab 命令 补全 命令 提示
查看>>