java简单的qq聊天源码.docx

上传人:b****7 文档编号:16028421 上传时间:2023-07-10 格式:DOCX 页数:5 大小:15KB
下载 相关 举报
java简单的qq聊天源码.docx_第1页
第1页 / 共5页
java简单的qq聊天源码.docx_第2页
第2页 / 共5页
java简单的qq聊天源码.docx_第3页
第3页 / 共5页
java简单的qq聊天源码.docx_第4页
第4页 / 共5页
java简单的qq聊天源码.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

java简单的qq聊天源码.docx

《java简单的qq聊天源码.docx》由会员分享,可在线阅读,更多相关《java简单的qq聊天源码.docx(5页珍藏版)》请在冰点文库上搜索。

java简单的qq聊天源码.docx

java简单的qq聊天源码

GetMessage.java服务端:

import;

import;

import;

import;

import;

import;

import;

import;

publicclassGetMessageextendsThread{

privateinti;

Stringv;

JLabellabel=null;

privateJTextAreatext;

publicGetMessage(inti,JTextAreatext){

this.i=i;

this.text=text;

}

publicvoidrun(){

try{

ServerSocketso=newServerSocket(i);

Sockets=so.accept();

while(true){

InputStreamReaderi=newInputStreamReader(s.getInputStream());

BufferedReaderb=newBufferedReader(i);

v=b.readLine();

text.append("对方说"+v+"\n");

}

}catch(IOExceptione){

//label.setText("对方已经下线");

text.append("对方下线了。

");

}

}

}

SendMessage.java客户端:

import;

import;

import;

import;

import;

import;

import;

import;

import;

publicclassSendMessageextendsThread{

privateStringip;

privateinti;

Sockets=null;

JLabellabel=null;

JTextFieldtext;

JTextAreatext1;

publicSendMessage(Stringip,inti,JTextAreatext1){

//TODOAuto-generatedconstructorstub

this.ip=ip;

this.i=i;

this.text1=text1;

}

publicvoidrun(){

while(true){

try{

s=newSocket(ip,i);

text1.setText("连接成功"+"\n");

break;

}catch(Exceptione){

try{

Thread.sleep(1000);

}catch(InterruptedExceptione1){

"出错了。

");

}

}

}

}

publicvoidsend(Stringmessage)

{

try{

PrintStreamp=newPrintStream(s.getOutputStream());

p.println(message);

}catch(Exceptione1){

"异常"+e1.getMessage());

}

}

}

Test.java简单的界面和测试类

importjava.awt.*;import;

import;

import;

importjava.util.*;importjavax.swing.*;

import;

classWindowTextAreaextendsJFrameimplementsActionListener

{

Strings;

JTextAreatext1;

JTextAreatext2;

JButtonbutton1,button2,button3;

SendMessaget2;

GetMessaget1;

JLabellable1,lable2;

JTextFieldtext;

WindowTextArea()

{this.s=s;

lable1=newJLabel("对方ip");

text=newJTextField(20);

text1=newJTextArea(6,18);

text2=newJTextArea(6,18);

text2.setEditable(false);

button1=newJButton("发送");

button2=newJButton("关闭");

button3=newJButton("确定ip");

setBounds(100,100,450,300);

setVisible(true);

Containercon=getContentPane();

con.setLayout(newFlowLayout());

con.add(lable1);

con.add(text);

con.add(button3);

con.add(newJScrollPane(text1));

con.add(newJScrollPane(text2));

con.add(button1);

con.add(button2);

button1.addActionListener(this);

button2.addActionListener(this);

button3.addActionListener(this);

con.validate();

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2