qqmainframe.java
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:6k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package client;
- import java.awt.BorderLayout;
- import java.awt.Choice;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.Panel;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.net.Socket;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Properties;
- import java.util.TreeSet;
- import javax.swing.DefaultListModel;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- public class qqmainframe {
- JFrame f;;
- Panel sp = new Panel();
- public static HashMap set = new HashMap();
- HashMap set1 = new HashMap();
- ObjectOutputStream oos;
- ObjectInputStream ois;
- JPanel p = new JPanel();
- JPanel jp2 = new JPanel();
- JPanel jp3 = new JPanel();
- Choice cc = new Choice();
- JButton jb = new JButton("群发");
- JButton jb1 = new JButton("退出");
- // JButton jb2=new JButton("退出");
- JScrollPane p1;
- Container c;
- qq_client vvv;
- String nam;
- int port;
- String ip;
- int port1;
- Socket so;
- DefaultListModel listModel = new DefaultListModel();
- JList jl = new JList(listModel);
- String sss;
- public qqmainframe(Socket soc,final ObjectOutputStream oos,ObjectInputStream ois,String nam1, String ip2, final int port,int port2) throws IOException {
- this.oos=oos;
- this.ois=ois;
- this.nam=nam1;
- this.ip=ip2;
- this.port1=port2;
- this.port=port;
- this.so=soc;
- f=new JFrame(nam);
- cc.add("我在线上");
- cc.add("隐身的我");
- cc.add("离线的我");
- cc.setSize(4, 17);
- p.setSize(200, 350);
- p1=new JScrollPane(jl);
- p.add(jl);
- // c=f.getContentPane();
- // c.add(p);
- jp2.add(cc);
- jp3.add(jb);
- jp3.add(jb);
- jp3.add(jb1);
- jl.setBackground(Color.cyan);
- jl.setSize(250,540);
- f.setSize(500,600);
- f.setVisible(true);
- f.add(jp2,BorderLayout.NORTH);
- f.add(jl,BorderLayout.CENTER);
- f.add(jp3,BorderLayout.SOUTH);
- f.setSize(100,400);
- f.setVisible(true);
- serverthread stre=new serverthread();
- stre.start();
- Thread t=new yonghuThread();
- serverthread.name=nam;
- serverthread.port=port1;
- t.start();
- jb.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- try {
- vvv= new qq_client(ip ,port,"群聊");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- jb1.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent arg0) {
- // TODO Auto-generated method stub
- System.exit(0);
- }
- }
- );
- jl.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // TODO Auto-generated method stub
- String name=String.valueOf(jl.getSelectedValue());
- String ss=set.get(name).toString();
- String[] arr=ss.split(":");
- System.out.println(arr[1]);
- try {
- System.out.println(arr[1]);
- qq_client q1=new qq_client(arr[1].substring(1,arr[1].length()),Integer.parseInt(arr[2]),name);
- } catch (NumberFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- cc.addItemListener(new ItemListener(){
- public void itemStateChanged(ItemEvent e) {
- TreeSet hs=new TreeSet();
- try {
- switch(cc.getSelectedIndex()){
- case 0:
- hs.add("A"+nam);
- hs.add("B"+ip);
- hs.add("C"+port1);
- oos.writeObject(hs);
- break;
- case 1:hs.add("*"+nam);
- oos.writeObject(hs); break;
- case 2: System.out.println("hllowoue");
- hs.add("?"+nam);
- oos.writeObject(hs); break;
- }
- }catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- }
- class yonghuThread extends Thread {
- public void run() {
- try {
- while (true) {
- Object oo = ois.readObject();
- // Object ooo=ois.readObject();
- ArrayList al=(ArrayList)oo;
- HashMap f=new HashMap();
- String[] str=al.get(0).toString().split(":");
- if(str.length==3){
- f.put(str[0],al.get(0).toString());
- for(int j=1;j<al.size();j++){
- str=al.get(j).toString().split(":");
- f.put(str[0],al.get(j).toString());
- }
- set=f;
- // set1=(HashMap)ooo;
- System.out.println(f);
- Object[] arr = set.keySet().toArray();
- listModel.removeAllElements();
- //listModel.removeAllElements();
- for (int i = 0; i < arr.length; i++) {
- listModel.addElement(arr[i].toString());
- }
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static void main(String s) {
- }
- }