⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qqclient.java

📁 可实现整个校园网内聊天
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.Date;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.text.SimpleDateFormat;
import java.util.StringTokenizer;
import java.applet.*;
import java.io.*;
import java.util.*;
import javax.media.*;
class kehuduan extends Frame implements ActionListener
{ Label label1,label2;
  TextField text1,text2;
  Button button1,button2,button3;
  InetAddress serveraddress;
  String address,host;
  String s=null;
  String zaixian;
  String zhujiao;
  String filename,filedata;
  DatagramPacket data_send=null,data_receive=null;
  DatagramSocket send=null,receive=null;
  SimpleDateFormat qq=new SimpleDateFormat("HH时mm分ss秒");
  SimpleDateFormat QQ=new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
  Box basebox,boxh1,boxh2,boxh3;
  Color  color=Color.cyan;
  kehuduan()
  {super("飞鸿2.0-登录界面");
   setSize(100,300);
   setBounds(300,300,300,140);
   setVisible(true);
   setResizable(false);
   label1=new Label("用户名");
   label2=new Label("密码");
   text1=new TextField(20);
   text2=new TextField(20);
   text2.setEchoChar('*');
   button1=new Button("登录    ");
   button2=new Button("注册");
   button3=new Button("修改飞鸿界面颜色");
   label1.setBackground(color);
   label2.setBackground(color);
   button1.setBackground(color);
   button2.setBackground(color);
   button3.setBackground(color);
   button1.addActionListener(this);
   button2.addActionListener(this);
   button3.addActionListener(this);
   basebox=Box.createHorizontalBox();
   boxh1=Box.createVerticalBox();
   boxh2=Box.createVerticalBox();
   boxh3=Box.createHorizontalBox();
   boxh3.add(button2);
   boxh3.add(button3);
   boxh1.add(label1);
   boxh1.add(label2);
   boxh1.add(button1);
   boxh2.add(text1);
   boxh2.add(text2);
   boxh2.add(boxh3);
   basebox.add(boxh1);
   basebox.add(boxh2);
   add(basebox);
   validate();
   addWindowListener (new WindowAdapter()
       {public void windowClosing(WindowEvent e)
          {System.exit(0);}
       }
    );
     try
    { InetAddress oo=InetAddress.getLocalHost();
      address=oo.getHostAddress();
      host=oo.getHostName();
      serveraddress=InetAddress.getByName("10.10.145.88"); //服务器端IP地址为10.10.145.88
    }
    catch(UnknownHostException e6) 
    {  
    }
   }
   public void actionPerformed(ActionEvent e)
   {if(e.getSource()==button1)//输入用户名和密码,发送给服务器端,进行登录验证
     {  
       String s1=text1.getText();
       zhujiao=s1;
       String s2=text2.getText();
       if(s1.equals("")||s2.equals(""))
       {JOptionPane.showMessageDialog(this,"用户名和密码不能为空!","提示",JOptionPane.WARNING_MESSAGE);
        return;
       }
        String nn="denglu"+','+s1+','+s2+','+address;
        byte buffer[]=nn.getBytes();
       try
       {data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);//客户端发送端口为9999,接收端口为8888
        send=new DatagramSocket();
        send.send(data_send);
        }
        catch(Exception e1) 
        {
        }
       byte data[]=new byte[88];
      try
      {data_receive=new DatagramPacket(data,data.length);
       receive=new DatagramSocket(8888);
      }
      catch(Exception e1)
       {
       }
        try
        {receive.receive(data_receive);
         int length=data_receive.getLength();
         String message=new String(data_receive.getData(),0,length);
          s=message;
          zaixian=s;
         }
         catch(Exception e4)
          {JOptionPane.showMessageDialog(this,"不能在同一个电脑上打开两个客户端!","提示",JOptionPane.WARNING_MESSAGE);
           return;
          }
    if(s.indexOf("yonghumingbucunzai")!=-1)//验证完毕,提交的用户不存在
     {JOptionPane.showMessageDialog(this,"该用户不存在","提示",JOptionPane.WARNING_MESSAGE);
       return;
     }
     else if(s.indexOf("mimachucuo")!=-1)//验证完毕,提交的密码错误
     {JOptionPane.showMessageDialog(this,"密码错误","提示",JOptionPane.WARNING_MESSAGE);
      return;
     }
     else if(s.indexOf("dengluchenggong")!=-1)//登录成功,进入主界面
     {dispose();
     qq jnj=new qq();
      return;
     }
    } 
     else if(e.getSource()==button2)//客户端请求注册,进入注册界面
     {zhuce gg=new zhuce();
     }
     else if(e.getSource()==button3)//修改客户端界面的颜色
     {color=JColorChooser.showDialog(this,"飞鸿界面颜色选择对话框",getBackground());
       button1.setBackground(color);
       button2.setBackground(color);
       button3.setBackground(color);
       label1.setBackground(color);
       label2.setBackground(color);
     }
   }
   class zhuce extends Frame implements ActionListener //注册界面
   { Label label1,label2,label3,label4,label5,label6,label7,label8;
     TextField text1,text2,text3,text4,text5,text6,text7,text8;
     Button button1;
     Box basebox,boxh1,boxh2;
     zhuce()
     {super("用户注册页面");
      setLayout(new BorderLayout());
      setSize(300,300);
      setBounds(300,300,300,300);
      setVisible(true);
      setBackground(color);
      label1=new Label("用户名");
      label2=new Label("密码");
      label3=new Label("确认密码");
      label4=new Label("学院");
      label5=new Label("班级");
      label6=new Label("QQ号");
      label7=new Label("手机号");
      label8=new Label("出生日期");
      text1=new TextField(20);
      text2=new TextField(20);
      text2.setEchoChar('*');
      text3=new TextField(20);
      text3.setEchoChar('*');
      text4=new TextField(20);
      text5=new TextField(20);
      text6=new TextField(20);
      text7=new TextField(20);
      text8=new TextField(20);
      text8.setText("19**-**-**");
      button1=new Button("注册");
      button1.setBackground(color);
      button1.addActionListener(this);
      basebox=Box.createHorizontalBox();
      boxh1=Box.createVerticalBox();
      boxh2=Box.createVerticalBox();
      boxh1.add(label1);
      boxh1.add(Box.createVerticalStrut(4));
      boxh1.add(label2);
      boxh1.add(Box.createVerticalStrut(4));
      boxh1.add(label3);
      boxh1.add(Box.createVerticalStrut(4));
      boxh1.add(label4);
      boxh1.add(Box.createVerticalStrut(4));
      boxh1.add(label5);
      boxh1.add(Box.createVerticalStrut(4));
      boxh1.add(label6);
      boxh1.add(Box.createVerticalStrut(4));
      boxh1.add(label7);
      boxh1.add(Box.createVerticalStrut(4));
      boxh1.add(label8);
      boxh2.add(text1);
      boxh2.add(Box.createVerticalStrut(4));
      boxh2.add(text2);
      boxh2.add(Box.createVerticalStrut(4));
      boxh2.add(text3);
      boxh2.add(Box.createVerticalStrut(4));
      boxh2.add(text4);
      boxh2.add(Box.createVerticalStrut(4));
      boxh2.add(text5);
      boxh2.add(Box.createVerticalStrut(4));
      boxh2.add(text6);
      boxh2.add(Box.createVerticalStrut(4));
      boxh2.add(text7);
      boxh2.add(Box.createVerticalStrut(4));
      boxh2.add(text8);
      boxh2.add(Box.createVerticalStrut(4));
      basebox.add(boxh1);
      basebox.add(boxh2);
      add(basebox,BorderLayout.NORTH);
      add(button1,BorderLayout.CENTER);
      validate();
      addWindowListener (new WindowAdapter()
       {public void windowClosing(WindowEvent e)
          {dispose();}
       }
      );
     }
     public void actionPerformed(ActionEvent e)
     { if(e.getSource()==button1)
       {String s1=text1.getText();
        String s2=text2.getText();
        String s3=text3.getText();
        String s4=text4.getText();
        String s5=text5.getText();
        String s6=text6.getText();
        String s7=text7.getText();
        String s8=text8.getText();
        if(s1.equals("")||s2.equals("")||s3.equals("")||s4.equals("")||s5.equals("")||s6.equals("")||s7.equals("")||s8.equals(""))
        {JOptionPane.showMessageDialog(this,"各选项不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
        else if(!s2.equals(s3))
        {JOptionPane.showMessageDialog(this,"两次输入的密码不一致,请重新输入","提示",JOptionPane.WARNING_MESSAGE);}
        else if((!s1.equals(""))&&(s2.equals(s3)))
        {
        try
        {
        String nn="zhuce"+','+s1+','+s2+','+s4+','+s5+','+s6+','+s7+','+s8;
        byte buffer[]=nn.getBytes();
        data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);
        send=new DatagramSocket();
        send.send(data_send);
       }
       catch(Exception e3) {}
       zhucejieshou();
     }
    }
  }
  public void zhucejieshou()//提交注册信息完毕后,等待服务器端发来的响应
  {
      byte data[]=new byte[88];
      try
      {data_receive=new DatagramPacket(data,data.length);
       receive=new DatagramSocket(8888);
      }
      catch(Exception e1) {}
        try
        {receive.receive(data_receive);
         int length=data_receive.getLength();
         String message=new String(data_receive.getData(),0,length);
          s=message;
         }
         catch(Exception e4) {}
      
     if(s.equals("zhucechenggong"))
     {JOptionPane.showMessageDialog(this,"注册成功","提示",JOptionPane.WARNING_MESSAGE);
      return;
     }
     else if(s.equals("yiyougaiyonghu"))
     {JOptionPane.showMessageDialog(this,"数据库中已有该用户,请更换用户名","提示",JOptionPane.WARNING_MESSAGE);
      return;
     }
  }
 }
 class qq extends Frame implements ActionListener,Runnable,ItemListener//主界面
 {JButton button,button2,button3,button4,button5;
  Label label1,label2,label3,label4,label5;
  Choice choice,choice2;
  TextArea text;
  TextField text1,text2,text3,text4,text5,text6,text8,text9;
  Box basebox,boxh1,boxh2,boxh3,boxh4,boxh5,boxh6;
  Thread shuaxin,accept;
  MenuBar menubar;
   Menu menu1,menu2,menu3,menu4;
   MenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9,item10;
   Player player;
   File file;
   URL mediaurl;
   BufferedReader bin;
   FileReader file_reader;
   BufferedWriter bout;
   FileWriter tofile;
   FileDialog   filedialog_save=new FileDialog(this,"保存文件对话框",FileDialog.SAVE);
   FileDialog  filedialog_open=new FileDialog(this,"打开文件对话框",FileDialog.LOAD);
  qq()
  {super("飞鸿2.0(Special for Postgraduate Of Nanjing University Of Posts & Telecommunications)");
  setSize(200,300);
  setBounds(200,200,650,420);
  setVisible(true);
  setBackground(color);
  setResizable(false);
  menubar=new MenuBar();
  menu1=new Menu("信息管理");
  menu2=new Menu("关机选项");
  menu3=new Menu("帮助");
  menu4=new Menu("附加功能");
    item1=new MenuItem("修改密码");
    item2=new MenuItem("修改个人信息");
    item3=new MenuItem("退出飞鸿客户端");
    item4=new MenuItem("注销");
    item5=new MenuItem("关机");
    item6=new MenuItem("重启");
    item7=new MenuItem("关于作者");
    item8=new MenuItem("发送文件");
    item9=new MenuItem("缘分测试");
    item10=new MenuItem("万年历");
    menu1.add(item1);
    menu1.addSeparator();
    menu1.add(item2);
    menu1.addSeparator();
    menu1.add(item3);
    menu2.add(item4);
    menu2.addSeparator();
    menu2.add(item5);
    menu2.addSeparator();
    menu2.add(item6);
    menu3.add(item7);
    menu4.add(item8);
    menu4.addSeparator();
    menu4.add(item9);
    menu4.addSeparator();
    menu4.add(item10);
    menubar.add(menu1);
    menubar.add(menu4);
    menubar.add(menu2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -