import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
class text02
{
public static void main(String[] args)
{
Frame ck=new Frame("B聊天室");
Button an=new Button("发送");
TextArea wbk1=new TextArea(10,40);
TextArea wbk2=new TextArea(10,40);
ck.setLayout(new FlowLayout());
ck.setBounds(100,200,350,420);
ck.add(wbk1);
ck.add(wbk2);
ck.add(an);
ck.setVisible(true);
new jie01(wbk1);
}
}
class jie01
{
private TextArea wbk;
jie01(TextArea wbk)
{
this.wbk=wbk;
jie();
}
public void jie()
{
try
{
DatagramSocket js=new DatagramSocket(1234);
while(true)
{
byte[]lin=new byte[1024];
DatagramPacket bao=new DatagramPacket(lin,0,lin.length);
js.receive(bao);
String ip=bao.getAddress().getHostAddress();
String nr=new String(bao.getData());
String k=ip+":"+nr;
wbk.append(k+"\r\n");//----------------------------------------------问题就在这,加了换行符就是不换行。。。!
}
}
catch (IOException a)
{
throw new RuntimeException("端口异常");
}
}
}
|
|