/**
* ClassName: CharFrame.java
* Author: qiujy
* CreateTime: 2009-4-22
* EMAIL: qjyong@gmail.com
* Copyright 2009 ++YONG All rights reserved.
*/
package client.ui;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.Date;
import javax.swing.*;
import client.*;
import client.model.entity.MyCellRenderer;
import client.model.entity.OnlineUserListModel;
import client.util.*;
import common.model.entity.*;
/** 聊天窗体 */
public class ChatFrame extends JFrame{
private static final long serialVersionUID = -2310785591507878535L;
/**聊天对方的信息Label*/
private JLabel otherInfoLbl;
/** 当前用户信息Lbl */
private JLabel currentUserLbl;
/**聊天信息列表区域*/
public static JTextArea msgListArea;
/**要发送的信息区域*/
public static JTextArea sendArea;
/** 在线用户列表 */
public static JList onlineList;
/** 在线用户数统计Lbl */
public static JLabel onlineCountLbl;
/** 准备发送的文件 */
public static FileInfo sendFile;
/** 私聊复选框 */
public JCheckBox rybqBtn;
public ChatFrame(){
this.init();
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setVisible(true);
}
public void init(){
this.setTitle("JQ聊天室");
this.setSize(550, 500);
this.setResizable(false);
//设置默认窗体在屏幕中央
int x = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int y = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setLocation((x - this.getWidth()) / 2, (y-this.getHeight())/ 2);
//左边主面板
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
//右边用户面板
JPanel userPanel = new JPanel();
userPanel.setLayout(new BorderLayout());
// 创建一个分隔窗格
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
mainPanel, userPanel);
splitPane.setDividerLocation(380);
splitPane.setDividerSize(10);
splitPane.setOneTouchExpandable(true);
this.add(splitPane, BorderLayout.CENTER);
//左上边信息显示面板
JPanel infoPanel = new JPanel();
infoPanel.setLayout(new BorderLayout());
//右下连发送消息面板
JPanel sendPanel = new JPanel();
sendPanel.setLayout(new BorderLayout());
// 创建一个分隔窗格
JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
infoPanel, sendPanel);
splitPane2.setDividerLocation(300);
splitPane2.setDividerSize(1);
mainPanel.add(splitPane2, BorderLayout.CENTER);
otherInfoLbl = new JLabel("当前状态:群聊中...");
infoPanel.add(otherInfoLbl, BorderLayout.NORTH);
msgListArea = new JTextArea();
msgListArea.setLineWrap(true);
infoPanel.add(new JScrollPane(msgListArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
JPanel tempPanel = new JPanel();
tempPanel.setLayout(new BorderLayout());
sendPanel.add(tempPanel, BorderLayout.NORTH);
// 聊天按钮面板
JPanel btnPanel = new JPanel();
btnPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
tempPanel.add(btnPanel, BorderLayout.CENTER);
//字体按钮
JButton fontBtn = new JButton(new ImageIcon("images/font.png"));
fontBtn.setMargin(new Insets(0,0,0,0));
fontBtn.setToolTipText("设置字体和格式");
btnPanel.add(fontBtn);
//表情按钮
JButton faceBtn = new JButton(new ImageIcon("images/sendFace.png"));
faceBtn.setMargin(new Insets(0,0,0,0));
faceBtn.setToolTipText("选择表情");
btnPanel.add(faceBtn);
//发送文件按钮
JButton shakeBtn = new JButton(new ImageIcon("images/shake.png"));
shakeBtn.setMargin(new Insets(0,0,0,0));
shakeBtn.setToolTipText("向对方发送窗口振动");
btnPanel.add(shakeBtn);
//发送文件按钮
JButton sendFileBtn = new JButton(new ImageIcon("images/sendPic.png"));
sendFileBtn.setMargin(new Insets(0,0,0,0));
sendFileBtn.setToolTipText("向对方发送文件");
btnPanel.add(sendFileBtn);
//私聊按钮
rybqBtn = new JCheckBox("私聊");
tempPanel.add(rybqBtn, BorderLayout.EAST);
//要发送的信息的区域
sendArea = new JTextArea();
sendArea.setLineWrap(true);
sendPanel.add(new JScrollPane(sendArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
// 聊天按钮面板
JPanel btn2Panel = new JPanel();
btn2Panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
this.add(btn2Panel, BorderLayout.SOUTH);
JButton closeBtn = new JButton("关闭");
closeBtn.setToolTipText("退出整个程序");
btn2Panel.add(closeBtn);
JButton submitBtn = new JButton("发送");
submitBtn.setToolTipText("按Enter键发送消息");
btn2Panel.add(submitBtn);
sendPanel.add(btn2Panel, BorderLayout.SOUTH);
//在线用户列表面板
JPanel onlineListPane = new JPanel();
onlineListPane.setLayout(new BorderLayout());
onlineCountLbl = new JLabel("在线用户列表(1)");
onlineListPane.add(onlineCountLbl, BorderLayout.NORTH);
//当前用户面板
JPanel currentUserPane = new JPanel();
currentUserPane.setLayout(new BorderLayout());
currentUserPane.add(new JLabel("当前用户"), BorderLayout.NORTH);
// 右边用户列表创建一个分隔窗格
JSplitPane splitPane3 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
onlineListPane, currentUserPane);
splitPane3.setDividerLocation(340);
splitPane3.setDividerSize(1);
userPanel.add(splitPane3, BorderLayout.CENTER);
//获取在线用户并缓存
DataBuffer.onlineUserListModel = new OnlineUserListModel(DataBuffer.onlineUsers);
//在线用户列表
onlineList = new JList(DataBuffer.onlineUserListModel);
onlineList.setCellRenderer(new MyCellRenderer());
//设置为单选模式
onlineList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
onlineListPane.add(new JScrollPane(onlineList,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
//当前用户信息Label
currentUserLbl = new JLabel();
currentUserPane.add(currentUserLbl);
///////////////////////注册事件监听器/////////////////////////
//关闭窗口
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
logout();
}
});
//关闭按钮的事件
closeBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
logout();
}
});
//选择某个用户私聊
rybqBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(rybqBtn.isSelected()){
User selectedUser = (User)onlineList.getSelectedValue();
if(null == selectedUser){
otherInfoLbl.setText("当前状态:私聊(选中在线用户列表中某个用户进行私聊)...");
}else if(DataBuffer.currentUser.getId() == selectedUser.getId()){
otherInfoLbl.setText("当前状态:想自言自语?...系统不允许");
}else{
otherInfoLbl.setText("当前状态:与 "+ selectedUser.getNickname()
+"(" + selectedUser.getId() + ") 私聊中...");
}
}else{
otherInfoLbl.setText("当前状态:群聊...");
}
}
});
//选择某个用户
onlineList.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
User selectedUser = (User)onlineList.getSelectedValue();
if(rybqBtn.isSelected()){
if(DataBuffer.currentUser.getId() == selectedUser.getId()){
otherInfoLbl.setText("当前状态:想自言自语?...系统不允许");
}else{
otherInfoLbl.setText("当前状态:与 "+ selectedUser.getNickname()
+"(" + selectedUser.getId() + ") 私聊中...");
}
}
}
});
//发送文本消息
sendArea.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
if(e.getKeyCode() == Event.ENTER){
sendTxtMsg();
}
}
});
submitBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
sendTxtMsg();
}
});
//发送振动
shakeBtn.addActionListener(new ActionListener() {
public void ac
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
jq.zip (99个子文件)
jq
.project 378B
bin
serverconfig.properties 131B
server
OnlineClientIOCache.class 713B
ServerMain.class 1KB
model
service
UserService.class 4KB
entity
OnlineUserTableModel.class 2KB
RegistedUserTableModel.class 2KB
controller
RequestProcessor.class 9KB
DataBuffer.class 2KB
ui
ServerInfoFrame$3.class 722B
ServerInfoFrame$2.class 691B
ServerInfoFrame$1.class 1KB
ServerInfoFrame.class 5KB
ServerMain$1.class 2KB
client
ClientThread.class 8KB
model
entity
MyCellRenderer.class 2KB
OnlineUserListModel.class 2KB
DataBuffer.class 2KB
ui
RegisterFrame.class 6KB
ChatFrame$1.class 655B
RegisterFrame$4.class 2KB
ChatFrame$2.class 686B
ChatFrame$7.class 690B
LoginFrame.class 5KB
RegisterFrame$3.class 1KB
LoginFrame$1.class 1KB
ChatFrame$6.class 688B
ChatFrame$4.class 2KB
ChatFrame.class 12KB
RegisterFrame$1.class 709B
ChatFrame$8.class 686B
ChatFrame$3.class 2KB
LoginFrame$3.class 688B
LoginFrame$2.class 700B
RegisterFrame$2.class 678B
ChatFrame$5.class 741B
ChatFrame$9.class 864B
ClientMain.class 2KB
util
JFrameShaker.class 2KB
ClientUtil.class 2KB
JFrameShaker$1.class 1KB
JFrameShaker$2.class 803B
common
model
entity
ResponseStatus.class 1KB
User.class 3KB
ResponseType.class 2KB
Response.class 3KB
FileInfo.class 2KB
Request.class 2KB
Message.class 1KB
util
IOUtil.class 944B
SocketUtil.class 845B
3rdLibs
substance.jar 1.75MB
.settings
org.eclipse.core.resources.prefs 107B
src
serverconfig.properties 131B
server
ServerMain.java 2KB
model
service
UserService.java 3KB
entity
OnlineUserTableModel.java 1KB
RegistedUserTableModel.java 1KB
OnlineClientIOCache.java 676B
controller
RequestProcessor.java 9KB
ui
ServerInfoFrame.java 4KB
DataBuffer.java 2KB
client
ClientThread.java 6KB
ClientMain.java 2KB
model
entity
OnlineUserListModel.java 1KB
MyCellRenderer.java 1KB
ui
RegisterFrame.java 5KB
ChatFrame.java 14KB
LoginFrame.java 5KB
util
ClientUtil.java 2KB
JFrameShaker.java 2KB
DataBuffer.java 2KB
common
model
entity
Request.java 1KB
User.java 3KB
ResponseType.java 552B
FileInfo.java 2KB
Response.java 2KB
Message.java 1KB
ResponseStatus.java 395B
util
IOUtil.java 823B
SocketUtil.java 753B
images
5.png 3KB
shake.png 675B
3.png 3KB
font.png 766B
logo.png 12KB
0.png 2KB
sendPic.png 786B
4.png 3KB
9.png 4KB
7.png 3KB
sendFace.png 819B
10.png 3KB
8.png 3KB
6.png 3KB
1.png 2KB
2.png 3KB
.classpath 324B
user.db 331B
共 99 条
- 1
资源评论
- 阿凡提的哥2014-06-07工程不错。可以正常运行。。唯一不足的是 登陆是如果登陆失败关闭后 服务端报nullpointException ,不够健壮
- jin_jesus2014-03-25非常好。值得学习
JoySeeDog
- 粉丝: 135
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功