回眸两笑百媚生 2014年02月09日
这个是我论文的最后一部分,急求大神帮忙脱坑,求大神帮忙解释详细一点
ManageQqChat.java里面是管理聊天界面的类里面是HashMap中放的是聊天界面的类
//这是一个管理聊天界面的类

package com.qq.client.tools;

import java.util.HashMap;

import com.qq.client.view.QqChat;

public class ManageQqChat {
private static HashMap hm = new HashMap<String, QqChat>();

//加入
public static void addQqChat(String loginIdAnFriendId ,QqChat qqChat) {
hm.put(loginIdAnFriendId, qqChat);

}


//取出

public static QqChat getQqChat(String loginIdAnFriendId) {
return (QqChat)hm.get(loginIdAnFriendId);


}
}

ManageQqFriendList.java里面是管理好友的界面的类,也是放在一个HashMap中
//管理好友,界面类



package com.qq.client.tools;

import java.util.HashMap;

import com.qq.client.view.QqFriendList;

public class ManageQqFriendList {
private static HashMap hm = new HashMap<String, QqFriendList>();
public static void addQqFriendList(String qqid, QqFriendList qqFriendList) {
hm.put(qqid, qqFriendList);

}

public static QqFriendList getQqFriendList(String qqId) {
return (QqFriendList)hm.get(qqId);

}
}
最后是con.qq.client.view包,里面放的是客户端的所有界面类
QqChat.java里面是放的聊天窗口:
//这是与好友聊天的界面
//因为客户端要处于读取的状态,因此我们要把它也要做成一个线程
package com.qq.client.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.qq.client.model.QqClientConServer;
import com.qq.client.tools.ManageClientConServerThread;
import com.qq.common.Message;
import com.qq.common.MessageType;

public class QqChat extends JFrame implements ActionListener {

JTextArea jta;
JTextField jtf;
JButton jb;
JPanel jp;
String ownerId;
String friendId;
public static void main(String...args) {
// QqChat qqChat = new QqChat("1");
}
public QqChat(String ownerId, String friend) {
this.ownerId = ownerId;
this.friendId = friend;

jta = new JTextArea();
jtf = new JTextField(15);
jb = new JButton("发送");
jb.addActionListener(this);
jp = new JPanel();
jp.add(jtf);
jp.add(jb);
this.add(jta, "Center");
this.add(jp, "South");
this.setTitle(ownerId + "正在和"+friend+"聊天 ");
this.setIconImage((new ImageIcon("image/xiaobaitu.png").getImage()));
this.setSize(300, 200);
this.setVisible(true);
}
//写一个方法,让它显示消息
public void showMessage(Message m) {
String info = m.getSender() + "对" + m.getGetter() + "说" + m.getCon() +"\r\n";
this.jta.append(info);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource() == jb) {
Message m = new Message();
m.setMesType(MessageType.message_comm_mes);
m.setSender(this.ownerId);
m.setGetter(this.friendId);
m.setCon(jtf.getText());
m.setSendTime(new Date().toString());
//发送给服务器
try {
ObjectOutputStream oos = new ObjectOutputStream(ManageClientConServerThread.getClientConServerThread(ownerId).getS().getOutputStream());
oos.writeObject(m);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// @Override
// public void run() {
// // TODO Auto-generated method stub
// while(true) {
// //读取 (一直等待)
// try {
// ObjectInputStream ois = new ObjectInputStream(QqClientConServer.s.getInputStream());
// Message m = (Message)ois.readObject();
// //显示到jta上
// String info = m.getSender() + "对" + m.getGetter() + "说: " + m.getCon() + "\r\n";
// this.jta.append(info);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// }
// }
}

QqClientLogin.java里面是登录界面:
//功能qq客户端登录界面
package com.qq.client.view;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import com.qq.client.model.QqClientUser;
import com.qq.client.tools.ManageClientConServerThread;
import com.qq.client.tools.ManageQqFriendList;
import com.qq.common.Message;
import com.qq.common.MessageType;
import com.qq.common.User;
public class QqClientLogin extends JFrame implements ActionListener{
//定义北面需要的组件
JLabel jbl1;
//定义中间需要的组件
//中部有三个JPanel,有一个叫选项卡窗口管理。
JTabbedPane jtp;
JPanel jp2, jp3, jp4;
JLabel jp2_jbl1, jp2_jbl2, jp2_jbl3, jp2_jbl4;
JButton jp2_jb1;
JTextField jp2_jtf;
JPasswordField jp2_jpf;
JCheckBox jp2_jcb1, jp2_jcb2;
//定义南部需要的组件,JPanel相当于白纸,上面可以放东西
JPanel jp1;
JButton jp1_jb1, jp1_jb2,jp1_jb3;
public static void main(String...args) {
QqClientLogin qqClientLogin = new QqClientLogin();
System.out.println();
}
public QqClientLogin(){
//处理北部
jbl1 = new JLabel(new ImageIcon("image/tou.gif"));
//处理中部
jp2 = new JPanel(new GridLayout(3, 3));
jp2_jbl1 = new JLabel("用户名",JLabel.CENTER);
jp2_jbl2 = new JLabel("密码",JLabel.CENTER);
jp2_jbl3 = new JLabel("忘记密码?",JLabel.CENTER);
jp2_jbl3.setForeground(Color.blue);
jp2_jbl4 = new JLabel("申请密码保护",JLabel.CENTER);
jp2_jbl4.setForeground(Color.blue);
jp2_jb1 = new JButton(new ImageIcon("image/clear.gif"));
jp2_jtf = new JTextField();
jp2_jpf = new JPasswordField();
jp2_jcb1 = new JCheckBox("隐身登录");
jp2_jcb2 = new JCheckBox("记住密码");
// 把控件按照顺序加入到jp2
jp2.add(jp2_jbl1);
jp2.add(jp2_jtf);
jp2.add(jp2_jb1);
jp2.add(jp2_jbl2);
jp2.add(jp2_jpf);
jp2.add(jp2_jbl3);
jp2.add(jp2_jcb1);
jp2.add(jp2_jcb2);
jp2.add(jp2_jbl4);

//创建选项卡窗口
jtp = new JTabbedPane();
jtp.add("系统帐号", jp2);
jp3 = new JPanel();
jtp.add("手机号码", jp3);
jp4 = new JPanel();
jtp.add("电子邮件", jp4);

//处理南部
jp1 = new JPanel();
jp1_jb1 = new JButton(new ImageIcon("image/denglu.gif"));
//响应用户点击登录,连接服务器
jp1_jb1.addActionListener(this);

jp1_jb2 = new JButton(new ImageIcon("image/quxiao.gif"));

jp1_jb3 = new JButton(new ImageIcon("image/xiangdao.gif"));

//把三个按钮放到jp1

jp1.add(jp1_jb1);
jp1.add(jp1_jb2);
jp1.add(jp1_jb3);


this.add(jbl1,"North");
this.add(jtp,"Center");
this.add(jp1, "South");
this.setSize(350,240);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);



}

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
//如果用户点击登录
if(arg0.getSource()==jp1_jb1){

QqClientUser qqClientUser = new QqClientUser();
User u = new User();
u.setUserId(jp2_jtf.getText().trim());
u.setPasswd(new String(jp2_jpf.getPassword()));

if(qqClientUser.checkUser(u)) {

//发送一个要求返回在线好友的请求包
try {
//把创建好友列表的语句提前否则的话不能成功的

QqFriendList qqList = new QqFriendList(u.getUserId());
ManageQqFriendList.addQqFriendList(u.getUserId(), qqList);

ObjectOutputStream oos = new ObjectOutputStream
(ManageClientConServerThread.getClientConServerThread
(u.getUserId()).getS().getOutputStream());

//做一个Message
Message m = new Message();
m.setMesType(MessageType.message_get_onLineFriend);
//指明我要的是这个qq号的好友情况
m.setSender(u.getUserId());

oos.writeObject(m);


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.dispose();
}else {

JOptionPane.showMessageDialog(this,"密码错误,请重新输入");
}

}

}
}

QqFriendList.java里面是放的好友列表的界面
//我的好友列表,还有陌生人和黑名单

package com.qq.client.view;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.qq.client.tools.ManageQqChat;
import com.qq.common.Message;

public class QqFriendList extends JFrame implements ActionListener, MouseListener{

...全文
145 点赞 收藏 9
写回复
9 条回复

还没有回复,快来抢沙发~

发动态
发帖子
非技术区
创建于2007-09-28

8086

社区成员

7.1w+

社区内容

Java 非技术区
社区公告
暂无公告