• 大小: 14KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: Java
  • 标签: 聊天系统  

资源简介

供大家学习 不要分哈! 这个聊天系统还有那个银行系统都是和同学一起做的哈!

资源截图

代码片段和文件信息

package Final_chat;
/*登陆成功之后要创建用户文件夹,之下有一个history文件夹,里边的txt文件以对方account命名*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.Socket;

import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Client extends Jframe implements ActionListenerRunnable{

private JButton logoutBt = new JButton(“下线“);
private JButton mutichat = new JButton(“群聊“);
private JButton beginChat = new JButton(“开始私聊“);
private JButton singlechat = new JButton(“私聊已开启“);
private boolean canMutiSelect = false;
private List userList = new List(150canMutiSelect);
private boolean canRUN = true;
private Socket socket = null;
private String account; 
private JPanel bottomPanel = new JPanel();
private JPanel topPanel = new JPanel();
private List departmentList = new List(150);

public Client(String accountSocket socketList userList){
this.account=account;
this.userList=userList;
this.settitle(this.account);

bottomPanel.setLayout(new GridLayout(11));
topPanel.setLayout(new GridLayout(11));

//chatLabel.setText(“私聊开启“);
this.getContentPane().add(topPanel BorderLayout.NORTH);
this.getContentPane().add(userList BorderLayout.WEST);
this.getContentPane().add(departmentList BorderLayout.EAST);
this.getContentPane().add(bottomPanel BorderLayout.SOUTH);
topPanel.setBackground(new Color(217228252));
topPanel.add(logoutBt);
topPanel.add(singlechat);
topPanel.add(beginChat);
bottomPanel.setBackground(new Color(217228252));
bottomPanel.add(mutichat);
//panel.add(chatLabel);
//panel.add(beginMutiChat);


userList.addActionListener(this);
logoutBt.addActionListener(this);
mutichat.addActionListener(this);
beginChat.addActionListener(this);
singlechat.addActionListener(this);

this.setSize(260600);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);

new Thread(this).start();
this.socket=socket;
}

public void run(){
try{
while(canRUN){
InfoPackage ip = SYSTEMIO.receive(socket);
System.out.println(“Purpose is “+ip.getPurpose());//getPurpose
if(ip.getPurpose().equals(“MSG“)){
Messageframe mf = new Messageframe(socketip.getAccount()this.account);
mf.infoTa.append(ip.getMessage() + “\r\n“);//新出现一个Messageframe,将收到的信息加到自己那个界面上
                 //将聊天记录储存在文件里
                    String change=““;
                    change=ip.getAccount();
                    ip.setAccount(ip.getTargetAccount());
                    ip.setTargetAccount(change);
Messageframe.saveHistory(ip);

}
else if(ip.getPurpose().equals(“REFRESH_USERS“)){

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       8506  2009-11-29 14:36  Final_chat\Client.java

     文件       8079  2009-11-29 02:04  Final_chat\History.java

     文件       1548  2009-11-29 14:26  Final_chat\InfoPackage.java

     文件       2988  2009-11-29 07:08  Final_chat\Login.java

     文件       6197  2009-11-29 03:59  Final_chat\Messageframe.java

     文件       5275  2009-11-29 06:53  Final_chat\Register.java

     文件      11703  2009-11-29 14:36  Final_chat\Server.java

     文件        805  2009-11-29 06:49  Final_chat\SYSTEMIO.java

     目录          0  2009-12-16 15:17  Final_chat

----------- ---------  ---------- -----  ----

                45101                    9


评论

共有 条评论