第一个JAVA文件:package com.crazy;
import java.net.*;
import java.awt.*;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;public class CrazyServer {

public static void main(String[] args) {
new RunServer().runServer();
new RunClient().runClient();
}




}
//发送...
class RunServer extends Frame implements ActionListener {
DatagramPacket dp = null;
DatagramSocket ds = null;
TextField tfText = new TextField(); TextArea ta = new TextArea();

byte[] buf = null;

public void runServer() {
//buf = new byte[1000];
/*buf = (new String("你也好")).getBytes();

try{

dp = new DatagramPacket(buf,buf.length,new InetSocketAddress("127.0.0.1",9090));

ds = new DatagramSocket(6060);
}catch(SocketException e1) {
e1.printStackTrace();
}catch(IOException e2) {
e2.printStackTrace();
}
try{
ds.send(dp);

}catch(IOException e) {
e.printStackTrace();
}


}*/
this.setTitle("CrazyServer");
setLocation(400, 300);
this.setSize(300, 300);
add(tfText, BorderLayout.SOUTH);
add(ta, BorderLayout.NORTH);
pack();


this.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent arg0) { System.exit(0);
} });
tfText.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
byte[] buf; buf = new String(tfText.getText()).getBytes(); try {

dp = new DatagramPacket(buf, buf.length/*,new InetSocketAddress("127.0.0.1",10000)*/);
dp.setSocketAddress(new InetSocketAddress("127.0.0.1", 10000)); 
ds = new DatagramSocket();
ds.send(dp);
String str = tfText.getText();
ta.setText(ta.getText() + str + '\n');
tfText.setText("");

} catch (IOException e1) {
e1.printStackTrace();


  }finally {
ds.close();
}
}}
//收取..
class RunClient {
DatagramPacket dp = null;
DatagramSocket ds = null;
//RunServer cse;
byte[] buf;

public void runClient() {

buf = new byte[1000];
//buf = (new String("你也好")).getBytes();

try{

dp = new DatagramPacket(buf,buf.length);

ds = new DatagramSocket(9090);
}catch(SocketException e1) {
e1.printStackTrace();
}catch(IOException e2) {
e2.printStackTrace();
}

while(true) {
try {


ds.receive(dp);

String str = new String(buf,0,dp.getLength());
//System.out.println(new String(buf,0,dp.getLength()));
System.out.println(str);

//cse.ta.setText(str);


} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}

}
}
}
第二个JAVA文件package com.crazy;
import java.net.*;
import java.awt.*;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;public class CrazyServer {

public static void main(String[] args) {
new RunServer().runServer();
new RunClient().runClient();
}




}
//发送...
class RunServer extends Frame implements ActionListener {
DatagramPacket dp = null;
DatagramSocket ds = null;
TextField tfText = new TextField(); TextArea ta = new TextArea();

byte[] buf = null;

public void runServer() {
//buf = new byte[1000];
/*buf = (new String("你也好")).getBytes();

try{

dp = new DatagramPacket(buf,buf.length,new InetSocketAddress("127.0.0.1",9090));

ds = new DatagramSocket(6060);
}catch(SocketException e1) {
e1.printStackTrace();
}catch(IOException e2) {
e2.printStackTrace();
}
try{
ds.send(dp);

}catch(IOException e) {
e.printStackTrace();
}


}*/
this.setTitle("CrazyServer");
setLocation(400, 300);
this.setSize(300, 300);
add(tfText, BorderLayout.SOUTH);
add(ta, BorderLayout.NORTH);
pack();


this.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent arg0) { System.exit(0);
} });
tfText.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
byte[] buf; buf = new String(tfText.getText()).getBytes(); try {

dp = new DatagramPacket(buf, buf.length/*,new InetSocketAddress("127.0.0.1",10000)*/);
dp.setSocketAddress(new InetSocketAddress("127.0.0.1", 10000)); 
ds = new DatagramSocket();
ds.send(dp);
String str = tfText.getText();
ta.setText(ta.getText() + str + '\n');
tfText.setText("");

} catch (IOException e1) {
e1.printStackTrace();


  }finally {
ds.close();
}
}}
//收取..
class RunClient {
DatagramPacket dp = null;
DatagramSocket ds = null;
//RunServer cse;
byte[] buf;

public void runClient() {

buf = new byte[1000];
//buf = (new String("你也好")).getBytes();

try{

dp = new DatagramPacket(buf,buf.length);

ds = new DatagramSocket(9090);
}catch(SocketException e1) {
e1.printStackTrace();
}catch(IOException e2) {
e2.printStackTrace();
}

while(true) {
try {


ds.receive(dp);

String str = new String(buf,0,dp.getLength());
//System.out.println(new String(buf,0,dp.getLength()));
System.out.println(str);

//cse.ta.setText(str);


} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}

}
}
}

两个文件相互间可以通信,但是不能显示在TexeArea 上,请高手帮一下忙.谢谢!