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

📄 好友界面.java

📁 我用JAVA写的QQ程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * 聊天界面.java
 *
 * Created on 2007年5月4日, 下午9:26
 */

package 客户端程序包;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.net.*;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import javax.swing.ProgressMonitorInputStream;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
//import org.w3c.dom.events.MouseEvent;
/**
 *
 * @author 王绿春   南昌大学软件学院045班
 */
public class 好友界面 extends javax.swing.JFrame implements Runnable ,java.awt.event.ActionListener{
    
    /** Creates new form 聊天界面 */
    public 好友界面(Socket Client_Soke,String QQNum,String Information,String RegisterState,String password) {
        initComponents();
        this.setBounds(800,150,200,565);
        Client_Socket=Client_Soke;
        QQNumber=QQNum;
        QQPassword=password;
        InforList=new ObjectArray();
        GroupMessage=new ObjectArray();
        //PeopleList=List;
        FriendList=new Vector(50,5);
        //ImageIcon img1 = new ImageIcon("picture/13.gif");
        Groups=new Vector(30,3);
        //*************************************************
        //Applet ap=new Applet();
        File f=new File("sound/msg.wav");
        try {
            MsgSound=Applet.newAudioClip(f.toURL());
            System.out.println("路径是:"+f.toURL().toString());
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
        //*************************************************
        
        ImageArray=new ImageIcon[15];
        for(int i=0;i<15;i++){
            String Index=Integer.toString(i);
            ImageArray[i]=new ImageIcon("picture/"+Index+".gif");
        }
        StringTokenizer St=new StringTokenizer(Information,"|");
        NickName=St.nextToken();
        TrueName=St.nextToken();
        Sex=St.nextToken();
        Age=St.nextToken();
        LeavingMessage=St.nextToken();
        Icon=St.nextToken();
        Sign=St.nextToken();
        Friend=St.nextToken();
        OnlineTime=St.nextToken();
        RequestList=St.nextToken();
        ResponseList=St.nextToken();
        GroupList=St.nextToken();
        MyGroup=St.nextToken();
        Message=St.nextToken();
        GroupLeavingMessage=St.nextToken();
        WhoIsOnLine=St.nextToken();
        System.out.println("群留言"+GroupLeavingMessage);
        State=RegisterState;
        ImageIcon img1 = new ImageIcon("picture/"+Icon+".gif"); 
        头像.setIcon(img1);
        头像.setText(NickName+"("+Sign+")");
        if(State.equals("1")){
            状态.setText("隐身");
            头像.setEnabled(false);
        }
        else{
            状态.setText("在线");
        }
        
        
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        容器 = new javax.swing.JPanel();
        好友标签 = new javax.swing.JLabel();
        查找 = new javax.swing.JButton();
        个人设置 = new javax.swing.JButton();
        头像 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        好友栏 = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        群 = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        状态 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("QQ-2006");
        setResizable(false);
        容器.setBackground(new java.awt.Color(255, 255, 255));
        容器.setForeground(new java.awt.Color(255, 153, 0));
        好友标签.setText("\u6211\u7684\u597d\u53cb\uff1a");

        查找.setText("\u67e5\u627e");
        查找.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                查找ActionPerformed(evt);
            }
        });
        查找.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                查找MouseClicked(evt);
            }
        });

        个人设置.setText("\u4e2a\u4eba\u8bbe\u7f6e");
        个人设置.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                个人设置MouseClicked(evt);
            }
        });

        头像.setBackground(new java.awt.Color(0, 153, 0));
        头像.setForeground(new java.awt.Color(255, 255, 0));
        头像.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                头像MouseClicked(evt);
            }
        });

        好友栏.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                好友栏MouseClicked(evt);
            }
        });

        jScrollPane1.setViewportView(好友栏);

        群.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                群MouseClicked(evt);
            }
        });

        jScrollPane2.setViewportView(群);

        jLabel1.setText("\u6211\u7684\u7fa4\uff1a");

        org.jdesktop.layout.GroupLayout 容器Layout = new org.jdesktop.layout.GroupLayout(容器);
        容器.setLayout(容器Layout);
        容器Layout.setHorizontalGroup(
            容器Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(容器Layout.createSequentialGroup()
                .addContainerGap()
                .add(容器Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .add(头像, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .add(容器Layout.createSequentialGroup()
                        .add(好友标签)
                        .add(16, 16, 16)
                        .add(状态))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, 查找, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .add(个人设置, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .add(jLabel1))
                .addContainerGap())
        );
        容器Layout.setVerticalGroup(
            容器Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(容器Layout.createSequentialGroup()
                .add(头像, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(容器Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(好友标签)
                    .add(状态))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 246, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(9, 9, 9)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(个人设置)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(查找)
                .addContainerGap(11, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(容器, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(容器, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void 群MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_群MouseClicked
// TODO 将在此处添加您的处理代码:
        int i=0;
        
        if(evt.getClickCount()==1){
        int index = 群.locationToIndex(evt.getPoint());
        JLabel lab=(JLabel) 群.getModel().getElementAt(index);
        String GroupNum=lab.getText();
        for(i=0;i<GroupMessage.GetLength();i++){
            if(flag0&&GroupMessage.GetMember(i).GetSender().equals(GroupNum)){
                群.setSelectedIndex(100);
                
                return;
            }
        }
        
        
        if(flag0){
            GroupMessage.AddNewMember(GroupNum,"");
        }
        flag0=true;
        群.setSelectedIndex(100);
        System.out.println("好友界面的SOCKET:"+Client_Socket);
        群聊界面 PublicChat=new 群聊界面(Client_Socket,GroupNum,QQNumber);
        PublicChat.setVisible(true);
        new Thread(PublicChat).start();
        }
        
        
    }//GEN-LAST:event_群MouseClicked

    private void 头像MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_头像MouseClicked
// TODO 将在此处添加您的处理代码:
        //System.out.println("点击了右键鼠标");
        if(evt.isPopupTrigger())
          System.out.println("点击了右键鼠标");
          getJPopupMenu().show(this,evt.getX(),evt.getY());

    }//GEN-LAST:event_头像MouseClicked

    private void 好友栏MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_好友栏MouseClicked
// TODO 将在此处添加您的处理代码:
       
        int i=0;
        
        if(evt.getClickCount()==1){
        int index = 好友栏.locationToIndex(evt.getPoint());
        JLabel lab=(JLabel) 好友栏.getModel().getElementAt(index);
        String s=lab.getText().substring(lab.getText().length()-9);
        String t=lab.getText().substring(0,lab.getText().length()-9);
        for(i=0;i<InforList.GetLength();i++){
            if(flag&&InforList.GetMember(i).GetSender().equals(s)){
                好友栏.setSelectedIndex(100);
                
                return;
            }
        }
        
        
        if(flag){
            InforList.AddNewMember(s,"");
        }
        flag=true;
        好友栏.setSelectedIndex(100);
        System.out.println("好友界面的SOCKET:"+Client_Socket);
        私聊界面 PrivateChat=new 私聊界面(Client_Socket,s,t,QQNumber);
        PrivateChat.setVisible(true);
        new Thread(PrivateChat).start();
        }
        
         
        
        
        
    }//GEN-LAST:event_好友栏MouseClicked

    private void 个人设置MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_个人设置MouseClicked
// TODO 将在此处添加您的处理代码:
        new 个人设置(Client_Socket,QQNumber,NickName,TrueName,Age,Sex,Icon,Sign,Friend).setVisible(true);
    }//GEN-LAST:event_个人设置MouseClicked

    private void 查找MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_查找MouseClicked
// TODO 将在此处添加您的处理代码:
        查找好友 FindFriend=new 查找好友(Client_Socket,QQNumber,NickName);
        FindFriend.setVisible(true);
        new Thread(FindFriend).start();
        
    }//GEN-LAST:event_查找MouseClicked

    private void 查找ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_查找ActionPerformed
// TODO 将在此处添加您的处理代码:
    }//GEN-LAST:event_查找ActionPerformed

public void SetFriendList(){
    
    try{
          
          StringTokenizer St=new StringTokenizer(Friend,"#");
          while(St.hasMoreTokens()){

⌨️ 快捷键说明

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