/**
* 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.rar (99个子文件)
jq
images
2.png 3KB
9.png 4KB
sendFace.png 819B
3.png 3KB
5.png 3KB
8.png 3KB
sendPic.png 786B
6.png 3KB
font.png 766B
1.png 2KB
0.png 2KB
logo.png 12KB
4.png 3KB
shake.png 675B
10.png 3KB
7.png 3KB
src
client
model
entity
MyCellRenderer.java 1KB
OnlineUserListModel.java 1KB
ui
ChatFrame.java 14KB
LoginFrame.java 5KB
RegisterFrame.java 5KB
util
JFrameShaker.java 2KB
ClientUtil.java 2KB
DataBuffer.java 2KB
ClientMain.java 2KB
ClientThread.java 6KB
server
ServerMain.java 2KB
controller
RequestProcessor.java 9KB
model
entity
RegistedUserTableModel.java 1KB
OnlineUserTableModel.java 1KB
service
UserService.java 3KB
ui
ServerInfoFrame.java 4KB
OnlineClientIOCache.java 676B
DataBuffer.java 2KB
serverconfig.properties 131B
common
model
entity
FileInfo.java 2KB
Message.java 1KB
ResponseStatus.java 395B
Response.java 2KB
Request.java 1KB
User.java 3KB
ResponseType.java 552B
util
SocketUtil.java 753B
IOUtil.java 823B
bin
client
model
entity
OnlineUserListModel.class 2KB
MyCellRenderer.class 2KB
DataBuffer.class 2KB
ClientMain.class 2KB
ui
RegisterFrame$4.class 2KB
ChatFrame$1.class 655B
RegisterFrame$3.class 1KB
ChatFrame$8.class 686B
LoginFrame$1.class 1KB
ChatFrame$9.class 864B
ChatFrame$2.class 686B
RegisterFrame$1.class 709B
RegisterFrame$2.class 678B
ChatFrame$4.class 2KB
ChatFrame.class 12KB
LoginFrame.class 5KB
ChatFrame$7.class 690B
LoginFrame$2.class 700B
RegisterFrame.class 6KB
ChatFrame$6.class 688B
ChatFrame$3.class 2KB
ChatFrame$5.class 741B
LoginFrame$3.class 688B
ClientThread.class 8KB
util
JFrameShaker.class 2KB
JFrameShaker$1.class 1KB
ClientUtil.class 2KB
JFrameShaker$2.class 803B
server
ServerMain.class 1KB
controller
RequestProcessor.class 9KB
model
entity
OnlineUserTableModel.class 2KB
RegistedUserTableModel.class 2KB
service
UserService.class 4KB
DataBuffer.class 2KB
ui
ServerInfoFrame$2.class 691B
ServerInfoFrame.class 5KB
ServerInfoFrame$3.class 722B
ServerInfoFrame$1.class 1KB
OnlineClientIOCache.class 713B
ServerMain$1.class 2KB
serverconfig.properties 131B
common
model
entity
User.class 3KB
Response.class 3KB
ResponseType.class 1KB
Request.class 2KB
FileInfo.class 2KB
ResponseStatus.class 1KB
Message.class 1KB
util
SocketUtil.class 845B
IOUtil.class 944B
.classpath 324B
.settings
org.eclipse.core.resources.prefs 107B
3rdLibs
substance.jar 1.75MB
.project 378B
user.db 268B
共 99 条
- 1
buddha17
- 粉丝: 37
- 资源: 56
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 施工人员检测37-YOLOv7、COCO、CreateML、Darknet、Paligemma、VOC数据集合集.rar
- 嵌入式系统课程设计:基于51单片机的温度检测系统实现
- BurpLoaderKeygen
- 工具变量-A股上市公司企业盟浪esg评级数据(2018-2022年).xlsx
- 施工人员检测26-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- springboot靓车汽车销售网站(代码+数据库+LW)
- java区块链项目模块代码.zip
- C++按层次遍历二叉树.zip
- 施工人员检测22-YOLOv9数据集合集.rar
- 工具变量-乡村旅游指标数据2007-2021年.xlsx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页