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

📄 好友界面.java

📁 我用JAVA写的QQ程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                   
                   continue;
             }
             if(Information.startsWith("New")){              //新加的好友列入好友名单
                   System.out.println("接到New");
                   if(Information.substring(3,4).equals("1")){
                        WhoIsOnLine=WhoIsOnLine+Information.substring(5,14)+"#";
                   }
                   Friend=Friend+Information.substring(4);
                   FriendList.clear();
                   SetFriendList();
                   continue;
                   
             }
             if(Information.startsWith("Pass")){
                   if(Information.substring(4).equals("T")){
                       JOptionPane.showMessageDialog(null,"恭喜!修改密码成功","恭喜",JOptionPane.INFORMATION_MESSAGE);
                   }
                   else{
                       JOptionPane.showMessageDialog(null,"遗憾!修改密码失败","遗憾",JOptionPane.INFORMATION_MESSAGE);
                   }
                   continue;
             }
             if(Information.startsWith("Member")){
                   RequireByFindMember=Information.substring(6);
                   continue;
             }
             if(Information.startsWith("newGroup")){
                  if(Information.startsWith("newGroupOK")){
                      JOptionPane.showMessageDialog(null,"恭喜!建群成功","恭喜",JOptionPane.INFORMATION_MESSAGE);
                  }
                  else{
                      JOptionPane.showMessageDialog(null,"遗憾!建群失败","遗憾",JOptionPane.INFORMATION_MESSAGE);
                  }
             }
             if(Information.startsWith("ReplyToRequestGroupMember")){
                   RequireByGroups=Information.substring(25);
                   System.out.println("成员列表"+RequireByGroups);
             }
             if(Information.startsWith("TransFile")){
                   String Number=Information.substring(9,18);
                   String Port=Information.substring(18,22);
                   String Address=Information.substring(22);
                   String Name=私聊界面.FindNickName(Number);
                   int selected=JOptionPane.showConfirmDialog(null,Name+"要给您传文件,接收?","消息",JOptionPane.YES_NO_OPTION);
                   if(selected==0){
                       SaveFile(Address);
                   }
                   else{
                       new SendAndReceive(Client_Socket,"ReTransFileRefuse").SendMessage();
                   }
             }
             if(Information.startsWith("ReTransFileFail")||Information.startsWith("ReTransFileRefuse")){
                   JOptionPane.showMessageDialog(null,"对方拒绝接受或不在线!","遗憾",JOptionPane.INFORMATION_MESSAGE);
                   私聊界面.TransFile.interrupt();
             }
             if(Information.startsWith("ChatRecordC")){
                   PrivateChatRecord=Information.substring(11);
                   System.out.println("聊天记录"+PrivateChatRecord);
             }
             if(Information.startsWith("ChatRecordG")){
                   GroupChatRecord=Information.substring(11);
                   System.out.println("聊天记录"+GroupChatRecord);
             }
               
             if(Information.startsWith("GroupMessage"))  //好友发来的信息
              {
                     String Group=Information.substring(12,16);
                     //String Speaker=Information.substring(16,20);
                     String Message=Information.substring(16);
                     System.out.println("发来的群消息:"+Message);
                     int i=0;
                     flag0=true;
                     boolean IsOnChat=false;
                     
                     for(i=0;i<好友界面.GroupMessage.GetLength();i++){
                        if( this.GroupMessage.GetMember(i).GetSender().equals(Group)){
                              System.out.println("错在这里");
                              this.GroupMessage.GetMember(i).SetMessage(Message);
                              int j=0;
                              for(j=0;j<Groups.size();j++){
                              JLabel lab=(JLabel) 群.getModel().getElementAt(j);
                              String s=lab.getText();
                              if(s.equals(Group)){
                                 this.群.setSelectedIndex(j);
                                 break;
                             }
                         }
                              IsOnChat=true;
                              break;
                        }
                    }
                                       
                    if(!IsOnChat){
                     
                         this.GroupMessage.AddNewMember(Group,Message);
                         int j=0;
                         for(j=0;j<Groups.size();j++){
                             JLabel lab=(JLabel) 群.getModel().getElementAt(j);
                             String s=lab.getText();
                             if(s.equals(Group)){
                                 this.群.setSelectedIndex(j);
                                 break;
                             }
                         }
                         flag0=false;
                    }
                    continue;                   
             }
                           
            } catch (IOException ex) {
                ex.printStackTrace();
                continue;
            }                
         }
     
           
    }
    public void SaveFile(String Addr){
          
          String Address=Addr;
          JFileChooser fc = new JFileChooser(); 
          int result = fc.showSaveDialog(好友界面.this); 
          File file1 = fc.getSelectedFile(); 
          String  fileName = file1.getAbsolutePath(); 
          System.out.println("fileName:"+fileName); 
          if (result == JFileChooser.APPROVE_OPTION){ 
                 try{ 
                        File file2=new File(fileName); 
                        file2.createNewFile(); 
                        RandomAccessFile raf=new RandomAccessFile(file2,"rw"); 
                         // 通过Socket连接文件服务器 
                        Socket server=new Socket(Address,7777); 
                        //创建网络接受流接受服务器文件数据 
                        InputStream netIn=server.getInputStream(); 
                        InputStream in=new DataInputStream(new BufferedInputStream(new ProgressMonitorInputStream(this,"Reading ",netIn)));
                        
                        //创建缓冲区缓冲网络数据 
                        byte[] buf=new byte[2048]; 
                        int num=in.read(buf); 
                        System.out.println("in.read(buf)′length="+num); 
                        while(num!=(-1)) {//是否读完所有数据 
                              raf.write(buf,0,num);//将数据写往文件 
                              raf.skipBytes(num);//顺序写文件字节 
                              num=in.read(buf);//继续从网络中读取文件 
                        } 
                        in.close(); 
                        raf.close(); 
                   } 
                   catch(Exception ex){ 
                         System.out.println(ex); 
                   } 

           } 
           if(result == JFileChooser.CANCEL_OPTION){ 
           } 
    }
    public void actionPerformed(ActionEvent e) {
        System.out.println("点击了右键鼠标处理");
        java.awt.datatransfer.Clipboard clipbd =new java.awt.datatransfer.Clipboard("");
        String command = e.getActionCommand();
        if(command.equalsIgnoreCase("上线")){
            System.out.println("点击了右键上线处理");
           PrintWriter GoOut;
           try {
               GoOut = new PrintWriter(Client_Socket.getOutputStream());
               GoOut.println("6"+QQNumber);
               GoOut.flush();
               State="1";
               状态.setText("在线");
               头像.setEnabled(true);
           } catch (IOException ex) {
            ex.printStackTrace();
             }
        }
            
        else if(command.equalsIgnoreCase("隐身")){
            System.out.println("点击了右键隐身处理");
            PrintWriter GoOut;
           try {
               GoOut = new PrintWriter(Client_Socket.getOutputStream());
               GoOut.println("7"+QQNumber);
               GoOut.flush();
               State="0";
               状态.setText("隐身");
               头像.setEnabled(false);
               
           } catch (IOException ex) {
            ex.printStackTrace();
             }
        }
            
        else if(command.equalsIgnoreCase("下线")){
               System.out.println("点击了右键下线处理");
               头像.setEnabled(false);
               
                PrintWriter GoOut;
           try {
               GoOut = new PrintWriter(Client_Socket.getOutputStream());
               GoOut.println("5"+QQNumber);
               GoOut.flush();
           } catch (IOException ex) {
            ex.printStackTrace();
             }
           this.dispose();
        }
            
        
    }
   private JPopupMenu getJPopupMenu(){
       jPopupMenu = new JPopupMenu();
       jPopupMenu.add(getOnMenuItem());
       jPopupMenu.add(getHideMenuItem());
       jPopupMenu.add(getOffMenuItem());
       return jPopupMenu;
 }

 private JMenuItem getOnMenuItem() {
  JMenuItem OnMenuItem = new JMenuItem();
  OnMenuItem.setText("上线");
  OnMenuItem.addActionListener(this);
  return OnMenuItem;
 }

 private JMenuItem getHideMenuItem() {
  JMenuItem HideMenuItem = new JMenuItem();
  HideMenuItem.setText("隐身");
  HideMenuItem.addActionListener(this);
  return HideMenuItem;
 }
 private JMenuItem getOffMenuItem() {
  JMenuItem OffMenuItem = new JMenuItem();
  OffMenuItem.setText("下线");
  OffMenuItem.addActionListener(this);
  return OffMenuItem;
 }
    
    
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton 个人设置;
    private javax.swing.JLabel 头像;
    private javax.swing.JLabel 好友标签;
    private javax.swing.JList 好友栏;
    private javax.swing.JPanel 容器;
    private javax.swing.JButton 查找;
    private javax.swing.JLabel 状态;
    private javax.swing.JList 群;
    // 变量声明结束//GEN-END:variables
    private Socket Client_Socket=null;
    private javax.swing.JLabel FriendLabel=null;
    public  static  ObjectArray InforList=null;
    public  static  ObjectArray GroupMessage=null;
    private  String QQNumber=null;
    private  Vector  FriendList=null;
    private  Vector Groups=null;
    private boolean flag=false;
    private boolean flag0=false;
    private ImageIcon[] ImageArray=null;
    private String NickName=null;
    private String TrueName=null;
    private String Sex=null;
    private String Age=null;
    private String LeavingMessage=null;
    private String Icon=null;
    private String Sign=null;
    public static String Friend=null;
    private String OnlineTime=null;
    private String RequestList=null;
    private String ResponseList=null;
    public static  String GroupList=null;
    public static  String MyGroup=null;
    private String Message=null;
    private String GroupLeavingMessage=null;
    private String WhoIsOnLine=null;
    private String State=null;
    private JPopupMenu jPopupMenu;
    public static String RequireByFindFriend=null;
    public static String RequireByFindMember=null;
    public static String QQPassword=null;
    public static String RequireByGroups=null;
    public static String PrivateChatRecord=null;
    public static String GroupChatRecord=null;
    private AudioClip MsgSound=null;
}
/*class CellRender extends JLabel implements ListCellRenderer{
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
         String s = value.toString();
         setText(s);
       
           if (isSelected) {
               setBackground(list.getSelectionBackground());
               setForeground(list.getSelectionForeground());
           }
         else {
               setBackground(list.getBackground());
               setForeground(list.getForeground());
           }
           setEnabled(list.isEnabled());
           setFont(list.getFont());
         setOpaque(true);
         return this;

    
    }

   
    
}*/
class MyListCellRenderer implements ListCellRenderer {
    public Component getListCellRendererComponent(JList list, 
                                                  Object value, 
                                                  int index, 
                                                  boolean isSelected, 
                                                  boolean cellHasFocus){
      JLabel lbl = (JLabel)value;
      lbl.setOpaque(true);      
      lbl.setBackground(isSelected ? Color.green : Color.white);
      lbl.setForeground(isSelected ? Color.white : Color.YELLOW);
      return lbl;
    }
  }



⌨️ 快捷键说明

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