?? 好友界面.java
字號:
/*
* 聊天界面.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 + -