java qq聊天界面代码_【附源码】用Java写了一个类QQ界面聊天小项目,可在线聊天!...

本文介绍了一个使用Java实现的QQ聊天界面项目,包括修改个人信息、添加删除好友、单聊等功能。项目中运用了Netty、Swing、集合同步阻塞队列、MySQL数据库等技术。详细讲解了各个功能的实现代码,如添加好友、删除好友、判断好友在线状态等。
摘要由CSDN通过智能技术生成

原标题:【附源码】用Java写了一个类QQ界面聊天小项目,可在线聊天!

目录:

1.功能实现

2.模块划分

3.使用到知识

4.部分代码实现

5.运行例图

1.功能实现

1.修改功能(密码、昵称、个性签名)

2.添加好友、删除好友

3.单聊功能

4.判断好友是否在线

2.模块划分

1bc6314125f8cd0196ed3fcbb1012707.png

3.使用的知识

netty

swing

集合等同步阻塞队列synchronousQueue

数据库MySQL中的CRUD

C3p0连接池

JSON字符串4.部分代码实现

1.nettyController.java

接收到来自客户端的消息,与dao层进行交互

dao层与之数据库进行交互

修改密码

f343b07e768740dc10b0adb6bc2f4792.png

添加好友

b351607af015533ad5fbb1364679e32f.png

从添加好友逻辑实现上我走了很多的弯路频繁的访问数据库,这是一件很不好的事情

packagechat.Project.controller;

importchat.Project.bean.information;

importchat.Project.constant.EnMsgType;

importchat.Project.dao.*;

importchat.utils.CacheUtil;

importchat.utils.JsonUtils;

importcom.fasterxml.jackson.databind.node.ObjectNode;

importio.netty.channel.Channel;

importjava.util.ArrayList;

importjava.util.Iterator;

publicclassNettyController{

privatestaticUserDao userDao = newUserDaoImpl;

privatestaticinformationDao informationDao = newinformationDaoImpl;

privatestaticfriendDao friendDao = newfriendDaoImpl;

publicstaticString processing(String message, Channel channel){

//解析客户端发送的消息

ObjectNode jsonNodes = JsonUtils.getObjectNode(message);

String msgtype = jsonNodes.get( "msgtype").asText;

if(EnMsgType.EN_MSG_LOGIN.toString.equals(msgtype)){

//登录操作

returnloginOperation(jsonNodes,channel);

} elseif(EnMsgType.EN_MSG_MODIFY_SIGNATURE.toString.equals(msgtype)){

//修改签名

returnmodifySignature(jsonNodes);

} elseif(EnMsgType.EN_MSG_MODIFY_NICKNAME.toString.equals(msgtype)){

//修改昵称

returnmodifyNickname(jsonNodes);

} elseif(EnMsgType.EN_MSG_GETINFORMATION.toString.equals(msgtype)){

//获取登录信息

returngetInformation(jsonNodes);

} elseif(EnMsgType.EN_MSG_VERIFY_PASSWORD.toString.equals(msgtype)){

//进行修改密码

returnverifyPasswd(jsonNodes);

} elseif(EnMsgType.EN_MSG_CHAT.toString.equals(msgtype)){

//单聊模式

returnSingleChat(jsonNodes);

} elseif(EnMsgType.EN_MSG_GET_ID.toString.equals(msgtype)){

//获取id

returngetId(jsonNodes);

} elseif(EnMsgType.EN_MSG_GET_FRIEND.toString.equals(msgtype)){

//获取好友列表

returngetFriend(jsonNodes);

} elseif(EnMsgType.EN_MSG_ADD_FRIEND.toString.equals(msgtype)){

//添加好友

returnaddFriends(jsonNodes);

} elseif(EnMsgType.EN_MSG_DEL_FRIEND.toString.equals(msgtype)){

//删除好友

returndelFriend(jsonNodes);

} elseif(EnMsgType.EN_MSG_ACTIVE_STATE.toString.equals(msgtype)){

//判断好友的在线状态

returnfriendIsActive(jsonNodes);

}

return"";

}

//判断好友在线状态

privatestaticString friendIsActive(ObjectNode jsonNodes){

intfriendId = jsonNodes.get( "friendId").asInt;

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

objectNode.put( "srctype",EnMsgType.EN_MSG_ACTIVE_STATE.toString);

//客户端保证用户独立存在且是好友

Channel channel = CacheUtil.get(friendId);

//判断用户是否在线

if(channel == null){

//用户不在线

objectNode.put( "code", 200);

} else{

//用户在线

objectNode.put( "code", 300);

}

returnobjectNode.toString;

}

//添加好友

privatestaticString delFriend(ObjectNode jsonNodes){

Integer friendId = jsonNodes.get( "friendId").asInt;

intuserId = jsonNodes.get( "id").asInt;

String localName = jsonNodes.get( "localName").asText;

//封装发回客户端的JSON

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

objectNode.put( "srctype",EnMsgType.EN_MSG_DEL_FRIEND.toString);

objectNode.put( "code", 200);

//验证是否存在当前好友

information information = informationDao.getInformation(friendId);

String friendName = information.getNickname;

//查询自己是否有该好友

booleanexist = friendDao.isExist(friendName,userId);

if(exist){

//存在当前好友进行删除操作

friendDao.delFriend(userId,friendName);

friendDao.delFriend(friendId,localName);

objectNode.put( "code", 300);

}

returnobjectNode.toString;

}

//添加好友

privatestaticString addFriends(ObjectNode jsonNodes){

Integer friendId = jsonNodes.get( "friendId").asInt;

intuserId = jsonNodes.get( "id").asInt;

String localName = jsonNodes.get( "localName").asText;

//验证是否有ID

booleanexists = userDao.verifyExistFriend(friendId);

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

objectNode.put( "srctype",EnMsgType.EN_MSG_ADD_FRIEND.toString);

objectNode.put( "code", 200);

if(exists){

//表示存在此id

objectNode.put( "code", 300);

//获取好友昵称

information information = informationDao.getInformation(friendId);

String friendNickname = information.getNickname;

//进行添加好友的操作 两个对应的信息都应该添加

friendDao.addFriends(userId,localName,friendNickname);

friendDao.addFriends(friendId,friendNickname,localName);

}

returnobjectNode.toString;

}

//获取好友列表

privatestaticString getFriend(ObjectNode jsonNodes){

intuid = jsonNodes.get( "uid").asInt;

//返回ArrayLis集合

ArrayList friends = friendDao.getFriends(uid);

//封装JSON

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

objectNode.put( "srctype",EnMsgType.EN_MSG_GET_FRIEND.toString);

//写回friend集合

Iterator iterator = friends.iterator;

inti = 0;

while(iterator.hasNext){

objectNode.put( "res"+i,iterator.next);

i++;

}

//记录好友个数

objectNode.put( "count",i);

returnobjectNode.toString;

}

//获取id

privatestaticString getId(ObjectNode jsonNodes){

String nickname = jsonNodes.get( "nickname").asText;

information information = informationDao.nicknameGetId(nickname);

//联系人的id

intuid = information.getUid;

//封装JSON

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

objectNode.put( "srctype",EnMsgType.EN_MSG_GET_ID.toString);

objectNode.put( "uid",uid);

returnobjectNode.toString;

}

//单聊模式

privatestaticString SingleChat(ObjectNode jsonNodes){

intid = jsonNodes.get( "id").asInt;

//根据id在friend表获取登录用户名

//封装JSON数据服务端转发数据

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

objectNode.put( "srctype",EnMsgType.EN_MSG_CHAT.toString);

//客户端保证用户独立存在且是好友

Channel channel = CacheUtil.get(id);

//判断用户是否在线

if(channel == null){

//用户不在线

objectNode.put( "code", 200);

} else{

//用户在线

objectNode.put( "code", 300);

//消息转发

channel.writeAndFlush(jsonNodes.toString);

}

returnobjectNode.toString;

}

//修改密码

privatestaticString verifyPasswd(ObjectNode jsonNodes){

intid = jsonNodes.get( "id").asInt;

String oldPasswd = jsonNodes.get( "oldPasswd").asText;

String newPasswd = jsonNodes.get( "newPasswd").asText;

booleanexits = userDao.verifyPassword(oldPasswd, id);

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_VERIFY_PASSWORD.toString);

objectNode.put( "code", 200);

if(exits){

//验证成功

userDao.modifyPasswd(newPasswd,id);

objectNode.put( "code", 300);

}

returnobjectNode.toString;

}

//获取信息

privatestaticString getInformation(ObjectNode jsonNodes){

intid = jsonNodes.get( "id").asInt;

information information = informationDao.getInformation(id);

//封装JSON发回客户端

ObjectNode objectNode = JsonUtils.getObjectNode;

objectNode.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

objectNode.put( "srctype",EnMsgType.EN_MSG_GETINFORMATION.toString);

objectNode.put( "Nickname",information.getNickname);

objectNode.put( "Signature",information.getSignature);

returnobjectNode.toString;

}

//修改昵称

privatestaticString modifyNickname(ObjectNode jsonNodes){

intid = jsonNodes.get( "id").asInt;

String nickname = jsonNodes.get( "nickname").asText;

//进行存储

informationDao.storeNickname(nickname,id);

return"";

}

//修改签名

privatestaticString modifySignature(ObjectNode jsonNodes){

intid = jsonNodes.get( "id").asInt;

String signature = jsonNodes.get( "signature").asText;

//进行存储

informationDao.storeSignature(signature,id);

return"";

}

//登录操作

privatestaticString loginOperation(ObjectNode objectNode,Channel channel){

intid = objectNode.get( "id").asInt;

String passwd = objectNode.get( "passwd").asText;

//进行数据库查询

booleanexits = userDao.getInformation(id, passwd);

ObjectNode jsonNodes = JsonUtils.getObjectNode;

jsonNodes.put( "msgtype",EnMsgType.EN_MSG_ACK.toString);

jsonNodes.put( "srctype",EnMsgType.EN_MSG_LOGIN.toString);

jsonNodes.put( "code", 300);

//返回状态码

if(exits){

jsonNodes.put( "code", 200);

//添加用户的在线信息

CacheUtil.put(id,channel);

}

returnjsonNodes.toString;

}

}

2.ClientHandler.java

客户端接受来自服务端返回的消息

根据返回的状态码来判断是否操作成功

packagechat.Project.netty;

importchat.Frame.chat.ChatFrame;

importchat.Frame.chat.linkmen;

importchat.Frame.chat.login;

importchat.Project.constant.EnMsgType;

importchat.util.JsonUtils;

importcom.fasterxml.jackson.databind.node.ObjectNode;

importio.netty.channel.ChannelHandlerContext;

importio.netty.channel.SimpleChannelInboundHandler;

importjava.util.concurrent.SynchronousQueue;

publicclassClientHandlerextendsSimpleChannelInboundHandler< String>{

//定义一个同步阻塞队列状态码

publicstaticSynchronousQueue queue = newSynchronousQueue<>;

publicstaticString Nickname;

publicString Signature;

@Override

protectedvoidchannelRead0(ChannelHandlerContext channelHandlerContext, String s)throwsException{

}

//客户端接收数据

@Override

publicvoidchannelRead(ChannelHandlerContext ctx, Object msg)throwsException{

System.out.println(msg);

//解析服务端发送的消息

ObjectNode jsonNodes = JsonUtils.getObjectNode((String) msg);

String msgtype = jsonNodes.get( "msgtype").asText;

if(EnMsgType.EN_MSG_ACK.toString.equals(msgtype)) {

String srctype = jsonNodes.get( "srctype").asText;

if(EnMsgType.EN_MSG_LOGIN.toString.equals(srctype)) {

//登录操作

queue.offer(jsonNodes.get( "code").asInt);

} elseif(EnMsgType.EN_MSG_GETINFORMATION.toString.equals(srctype)){

//存取信息

Nickname = jsonNodes.get( "Nickname").asText;

Signature = jsonNodes.get( "Signature").asText;

linkmen.label_1.setText(Nickname);

linkmen.field.setText(Signature);

} elseif(EnMsgType.EN_MSG_CHAT.toString.equals(srctype)){

//发送端返回消息

queue.offer(jsonNodes.get( "code").asInt);

} elseif(EnMsgType.EN_MSG_GET_ID.toString.equals(srctype)){

intuid = jsonNodes.get( "uid").asInt;

queue.offer(uid);

} elseif(EnMsgType.EN_MSG_GET_FRIEND.toString.equals(srctype)){

//获取登录用户的好友

intcount = jsonNodes.get( "count").asInt;

login.friend = newString[count];

for( inti = 0;i

login.friend[i] = jsonNodes.get( "res"+i).asText;

System.out.println(jsonNodes.get( "res"+i));

}

} elseif(EnMsgType.EN_MSG_ADD_FRIEND.toString.equals(srctype)){

//添加好友

queue.offer(jsonNodes.get( "code").asInt);

} elseif(EnMsgType.EN_MSG_DEL_FRIEND.toString.equals(srctype)){

//删除好友

queue.offer(jsonNodes.get( "code").asInt);

} elseif(EnMsgType.EN_MSG_ACTIVE_STATE.toString.equals(srctype)){

//好友在线状态

queue.offer(jsonNodes.get( "code").asInt);

}

} elseif(EnMsgType.EN_MSG_VERIFY_PASSWORD.toString.equals(msgtype)){

//修改密码

intcode = 0;

code = jsonNodes.get( "code").asInt;

queue.offer(code);

} elseif(EnMsgType.EN_MSG_CHAT.toString.equals(msgtype)){

//接收端接受消息 封装朋友昵称

String message = " "+ jsonNodes.get( "message").asText;

//聊天显示框读取消息

ChatFrame.sb.append(message+ "n");

ChatFrame.displayTextPanel.setText(ChatFrame.sb.toString);

}

}

}

3.linkmen.java

这是登录成功的界面

packagechat.Frame.chat;

importchat.Frame.operation.alterColumn.changeNickname;

importchat.Frame.operation.alterColumn.changePassword;

importchat.Frame.operation.alterColumn.changeSignature;

importchat.Frame.operation.friendHandle.addFriend;

importchat.Frame.operation.friendHandle.delFriend;

importchat.Frame.tipFrame;

importchat.Project.services.sendServers;

importio.netty.channel.Channel;

importjavax.swing.*;

importjavax.swing.event.ListSelectionEvent;

importjavax.swing.event.ListSelectionListener;

importjava.awt.*;

importjava.awt.event.ItemEvent;

importjava.awt.event.ItemListener;

/**

* 联系人界面

*/

publicclasslinkmenextendsJFrame{

//容器

privateJFrame frame;

//标签

privateJLabel label_2, label_3, label_4, label;

//昵称

publicstaticJLabel label_1;

//状态框

privateJComboBox box, box_1, box_2;

//图片

privateImageIcon icon_1, icon;

//文本

privateJTextField field_1;

//个性签名

publicstaticJTextField field;

//面板

privateJPanel panel_1, panel_3, panel;

//滚动面板

publicJScrollPane panel_2;

//列表

publicstaticJList list;

//与服务端通信的通道

privateChannel channel;

//用户的id

privateInteger id;

//暂存oldPasswd

publicstaticJLabel label_5,label_6;

//好友列表数组

privateString[] fd;

//列表

publicstaticDefaultListModel model;

publiclinkmen(Integer id, Channel channel,String[] fd){

this.id = id;

this.channel = channel;

this.fd = fd;

}

publicvoidinit{

//初始化面板1并设置信息

panel_1 = newJPanel;

panel_1.setLayout( null);

panel_1.setLocation( 0, 0);

panel_1.setBorder(BorderFactory.createTitledBorder( "资料卡"));

panel_1.setSize( newDimension( 295, 148));

panel_1.setOpaque( false);

//初始化面板3并设置信息

panel_3 = newJPanel;

panel_3.setLayout( null);

panel_3.setBorder(BorderFactory.createTitledBorder( "系统设置"));

panel_3.setLocation( 0, 617);

panel_3.setSize( newDimension( 295, 55));

panel_3.setOpaque( false);

//设置头像标签

label_2 = newJLabel( newImageIcon( "E:聊天软件untitledsrcimageSource4.png"));

label_2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

label_2.setBounds( 15, 15, 100, 100);

panel_1.add(label_2);

//初始暂存标签

label_5 = newJLabel;

label_6 = newJLabel;

//设置昵称标签

label_1 = newJLabel( "");

label_1.setBounds( 130, 10, 100, 30);

label_1.setFont( newFont( "宋体", Font.PLAIN, 18));

panel_1.add(label_1);

list = newJList(model);

//设置每个列表的高

list.setFixedCellHeight( 20);

list.setSelectionBackground( newColor( 0xD8FF2F));

list.addListSelectionListener( newListSelectionListener {

@Override

publicvoidvalueChanged(ListSelectionEvent e){

//打开一个聊天窗口

if(e.getValueIsAdjusting) {

for( inti = 0; i < model.size; i++) {

if(model.get(i).equals(list.getSelectedValue)){

//获取id有错误

intids = newsendServers(channel).getId((String) list.getSelectedValue);

if(ids!= 0) {

newsendServers(channel).friendIsActive(ids);

newChatFrame(ids, channel).setVisible( true);

} else{

System.out.println( "好友不存在");

}

}

}

}

}

});

//初始化面板二

panel_2 = newJScrollPane(list);

panel_2.setBorder(BorderFactory.createTitledBorder( "联系人"));

panel_2.setLocation( 0, 147);

panel_2.setSize( newDimension( 295, 470));

panel_2.getViewport.setOpaque( false);

list.setOpaque( false);

panel_2.setOpaque( false);

//设置在线状态bBox;

box = newJComboBox;

box.addItem( "✅在线");

box.addItem( "uD83DuDCBF隐身");

box.addItem( "uD83DuDCBB忙碌");

box.addItem( "❎离线");

box.setBounds( 200, 10, 70, 30);

panel_1.add(box);

//设置个性签名的标签

label_4 = newJLabel( "个性签名:");

label_4.setFont( newFont( "宋体", Font.PLAIN, 16));

label_4.setForeground(Color.BLUE);

label_4.setBounds( 120, 50, 100, 20);

panel_1.add(label_4);

//设置文本

field = newJTextField( "");

field.setBounds( 120, 80, 160, 30);

panel_1.add(field);

label_3 = newJLabel( "uD83DuDD0D");

label_3.setForeground(Color.RED);

label_3.setBounds( 10, 122, 20, 20);

panel_1.add(label_3);

//设置搜索栏

field_1 = newJTextField;

field_1.setBounds( 30, 120, 250, 25);

panel_1.add(field_1);

//对面板三进行初始化

box_1 = newJComboBox;

box_1.addItem( "uD83DuDD12uD83DuDD28uD83DuDD13");

box_1.addItem( "修改密码");

box_1.addItem( "修改昵称");

box_1.addItem( "修改签名");

box_1.setBounds( 8, 20, 100, 25);

panel_3.add(box_1);

box_1.addItemListener( newItemListener {

@Override

publicvoiditemStateChanged(ItemEvent e){

if( "修改签名".equals(box_1.getSelectedItem)) {

//执行一次

if(e.getStateChange == ItemEvent.SELECTED) {

changeSignature changeSignature = newchangeSignature(linkmen. this);

changeSignature.setVisible( true);

field.setText(changeSignature.jTextField.getText);

String signature = field.getText;

//存储签名的方法

newsendServers(channel).modifySignature(signature, id);

}

}

if( "修改密码".equals(box_1.getSelectedItem)) {

if(e.getStateChange == ItemEvent.SELECTED) {

changePassword changePassword = newchangePassword(linkmen. this);

changePassword.setVisible( true);

label_5.setText(changePassword.oldPassword.getText);

String oldPasswd = label_5.getText;

label_6.setText( newString(changePassword.newPassword.getPassword));

String newPasswd = label_6.getText;

//进行验证

newsendServers(channel).verifyPasswd(oldPasswd, id,newPasswd);

}

}

if( "修改昵称".equals(box_1.getSelectedItem)) {

if(e.getStateChange == ItemEvent.SELECTED) {

changeNickname changeNickname = newchangeNickname(linkmen. this);

changeNickname.setVisible( true);

label_1.setText(changeNickname.jTextField.getText);

String nickname = label_1.getText;

//存储昵称

newsendServers(channel).modifyNickname(nickname, id);

}

}

}

});

//添加好友、删除好友

box_2 = newJComboBox;

box_2.addItem( "uD83DuDC65");

box_2.addItem( "添加好友");

box_2.addItem( "删除好友");

box_2.setBounds( 170, 20, 100, 25);

box_2.addItemListener( newItemListener {

@Override

publicvoiditemStateChanged(ItemEvent e){

if( "添加好友".equals(box_2.getSelectedItem)) {

if(e.getStateChange == ItemEvent.SELECTED) {

addFriend addFriend = newaddFriend(linkmen. this);

addFriend.setVisible( true);

//读取要搜索的ID

String friendIds = addFriend.jTextField.getText;

//判断是否是字符串

if(judgeDigit(friendIds)){

intfriendId = Integer.parseInt(friendIds);

//搜索数据库

newsendServers(channel).addFriendOperate(friendId,id,label_1.getText);

} else{

newtipFrame.init( "输入参数错误");

}

}

}

if( "删除好友".equals(box_2.getSelectedItem)) {

if(e.getStateChange == ItemEvent.SELECTED) {

delFriend delFriend = newdelFriend(linkmen. this);

delFriend.setVisible( true);

//对其数据库进行删除操作

String friendIds = delFriend.TextField.getText;

//判断是否是字符串

if(judgeDigit(friendIds)){

intfriendId = Integer.parseInt(friendIds);

//操作数据库

newsendServers(channel).delFriendOperate(friendId,id,label_1.getText);

} else{

newtipFrame.init( "输入参数错误");

}

}

}

}

});

panel_3.add(box_2);

//设置frame信息

frame = newJFrame;

//设置窗体信息

frame.setTitle( "腾讯QQ");

//给窗体设置图片

icon_1 = newImageIcon( "E:聊天软件untitledsrcimageSource3.png");

frame.setIconImage(icon_1.getImage);

icon = newImageIcon( "E:聊天软件untitledsrcimageSource5.png");

label = newJLabel(icon);

//获取窗口的第二层,将label放入

frame.getLayeredPane.add(label, newInteger(Integer.MIN_VALUE));

//获取frame的顶层容器,并设置为透明

panel = (JPanel) frame.getContentPane;

panel.setOpaque( false);

frame.setLayout( null);

frame.setLocation( 750, 150);

frame.setSize( 287, 700);

frame.setVisible( true);

frame.setResizable( false);

label.setBounds( 0, 0, 287, 700);

frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

frame.add(panel_1);

frame.add(panel_2);

frame.add(panel_3);

}

publicvoidmian{

//初始化面板2并设置信息

model = newDefaultListModel<>;

for( inti = 0; i < fd.length; i++) {

model.addElement(fd[i]);

}

init;

//更新昵称和签名

newsendServers(channel).update(id);

//获取用户的昵称,和好友列表

//设置签名和昵称字体初始样式和大小

label_1.setFont( newFont( "宋体", Font.PLAIN, 18));

field.setFont( newFont( "宋体", Font.PLAIN, 18));

}

//判断是否是数字

privatestaticbooleanjudgeDigit(String string){

for( inti = 0; i < string.length; i++) {

if(!Character.isDigit(string.charAt(i))){

returnfalse;

}

}

returntrue;

}

}

4.tipFrame

提示操作状态窗口

packagechat.Frame;

importchat.Frame.chat.linkmen;

importchat.Frame.operation.alterColumn.changeNickname;

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

publicclasstipFrameextendsJDialog{

privateContainer container;

//显示错误信息

publicJLabel label;

//确认按钮

privateJButton button;

publictipFrame{

}

publicvoidinit(String msg){

container = getContentPane;

label = newJLabel(msg);

label.setBounds( 70, 0, 200, 70);

label.setFont( newFont( "微软雅黑",Font.PLAIN, 20));

container.add(label);

button = newJButton( "确认");

button.setBounds( 35, 50, 140, 40);

container.add(button);

setBounds( 780, 170, 220, 140);

setLayout( null);

setVisible( true);

container.setBackground( newColor( 0xD8FFD5));

//提示窗口前置

setAlwaysOnTop( true);

button.addActionListener( newActionListener {

@Override

publicvoidactionPerformed(ActionEvent e){

tipFrame. this.dispose;

}

});

}

}

5.运行例图

1.登录界面

9f832418a5684d68cf6640d4de2ad3fc.png

注册账号和忘记密码没有添加事件现在就是个摆设

2.联系人界面

02aa0a8f24df640e6e24e0f721ba28e4.png

这里面的所有功能都可以使用

3.聊天界面

41a680a2abf4c018d798619164178768.png

这个里面表情按钮没弄好

4.通信的过程

ca72dd59f682d3bb001b370de3a4de4d.png

5.修改操作

4669478d259cd509e69a194e6959788b.png

6.好友的操作

ef35f9b231b5d3b67a1aae19e852f6c1.png

责任编辑:

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值