⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatlisten.java

📁 QQ聊天
💻 JAVA
字号:
package com.sato.client.chat;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import javax.swing.JOptionPane;

import com.sato.pub.PackType;
import com.sato.pub.QQpack;
import com.sato.pub.User;

public class ChatListen implements ActionListener{
	private ChatFace chatFace;
	private ObjectOutputStream oos;
	private ObjectInputStream ois;
	public ChatListen(ChatFace chatFace,ObjectOutputStream oos,ObjectInputStream ois){
		this.chatFace=chatFace;
		this.oos=oos;
		this.ois=ois;
	}
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getActionCommand().equals("聊天记录")){
			
			try {
				FileReader fr=new FileReader("./chatRecord/"+chatFace.getId()+".txt");
				BufferedReader	br=new BufferedReader(fr);
				String str;
				while((str=br.readLine())!=null){
					chatFace.getRecordArea().append(str+"\n");
				}
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			chatFace.getRecordBt().setActionCommand("隐藏");
			chatFace.setSize(600, 610);
			chatFace.getSouthPanel().setVisible(true);
			chatFace.validate();
		}
		else if(e.getActionCommand().equals("隐藏")){
			chatFace.getSouthPanel().setVisible(false);
			chatFace.getRecordBt().setActionCommand("聊天记录");
			chatFace.setSize(600, 500);
			chatFace.validate();
		}
		else if(e.getSource().equals(chatFace.getSendBt())){
			QQpack qqpack=new QQpack();
			User from=new User();
			User to=new User();
			if(chatFace.getChatArea().getText().equals("")){
				JOptionPane.showConfirmDialog(null, "内容不能为空", "提示",JOptionPane.DEFAULT_OPTION);
				return;
			}
			else if(chatFace.getOnlineList().getSelectedValue().toString().equals("群聊")){
				qqpack.setType(PackType.group_chat);
				from.setSid(chatFace.getId());
				from.setSname(chatFace.getName());
				qqpack.setFrom(from);
				qqpack.setContent(chatFace.getChatArea().getText());
				try {
					oos.writeObject(qqpack);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				chatFace.getChatArea().setText("");
			}
			else{
				qqpack.setType(PackType.Private_Chat);
				String rs=chatFace.getOnlineList().getSelectedValue().toString();
				String[] result=rs.split("\\(");
				to.setSid(result[1].substring(0, 5));
				to.setSname(result[0]);
				from.setSid(chatFace.getId());
				from.setSname(chatFace.getName());
				qqpack.setTo(to);
				qqpack.setFrom(from);
				qqpack.setContent(chatFace.getChatArea().getText());
				try {
					oos.writeObject(qqpack);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				chatFace.getChatArea().setText("");
			}
		}
		else if(e.getSource().equals(chatFace.getCloseBt())){
			QQpack qqpack=new QQpack();			
			qqpack.setContent(chatFace.getId());
			qqpack.setType(PackType.offline);
			try {
				oos.writeObject(qqpack);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			System.exit(0);
		}
		else if(e.getSource().equals(chatFace.getChangePw())){
			new Dialog(oos,chatFace,ois);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -