qqmainframe.java.svn-base
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:4k
源码类别:
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.ItemListener;
- 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 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=new JFrame();
- JList jl=new JList();
- Panel sp=new Panel();
- HashMap set = 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;
- public qqmainframe(String s,int b) throws IOException {
- cc.add("我在线上");
- cc.add("隐身的我");
- cc.add("离线的我");
- p.setSize(90, 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.blue);
- jl.setSize(90,450);
- f.setSize(110,500);
- f.setVisible(true);
- f.add(jp2,BorderLayout.NORTH);
- f.add(p,BorderLayout.CENTER);
- f.add(jp3,BorderLayout.SOUTH);
- f.setSize(100,400);
- f.setVisible(true);
- Socket s1 = new Socket(s,b);
- oos=new ObjectOutputStream(s1.getOutputStream());
- ois =new ObjectInputStream(s1.getInputStream());
- System.out.println(ois);
- sp.add(jl);
- Thread t=new yonghuThread();
- t.start();
- }
- class yonghuThread extends Thread{
- public void run(){
- try {
- while(true){
- Object oo=ois.readObject();
- while(oo!=null){
- set=(HashMap)oo;
- }
- Object[] arr=set.keySet().toArray();
- if(0 == jl.getModel().getSize())
- {
- DefaultListModel listModel = new DefaultListModel();
- //操作这个集合
- listModel.add(0,arr[0].toString());
- //将这个集合添加到JList中
- jl.setModel(listModel);
- }
- //JList的项不为空时
- else
- {
- for(int i = 1; i < set.size(); i++){
- //从JList中获得这个集合,转换为默认项集合类型
- DefaultListModel listModel= (DefaultListModel) jl.getModel();
- //追加元素
- listModel.add(listModel.getSize(),arr[i].toString());
- //将这个集合添加到JList中
- jl.setModel(listModel);
- }
- }
- f.repaint();
- }
- } 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){
- }
- }