package UDP;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
/*
*
*需求:编写一个类似qq那样可以聊天的可视化图像界面,实现功能
*1)用户输入文字可以显示在公共区域(所有人都可以看见)
* 2015年9月8日
*/
/**
* 接收显示在公共区域信息的类
*/
class rev_Message implements Runnable {
MulticastSocket s = null;
rev_Message(MulticastSocket s) {
this.s = s;
}
@Override
public void run() {
while (true) {
// 2,定义数据包,用于存储数据
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, 0, buf.length);
try {
System.out.println("wait connect...");
// 3,通过Socket的receive方法接收数据
s.receive(dp);
// 4,通过数据包的方法提取包中的数据,打印
System.out.println("ip:" + dp.getAddress().getHostAddress()
+ " ||port:" + dp.getPort());
String str = new String(dp.getData(), 0, dp.getData().length);
System.out.println("----->data:" + str);
String str1 = new String("ip:" + dp.getAddress() + "||"
+ "port:" + dp.getPort());
createMenu.getTxr_rev().append(
"\r\n" + str1 + "\r\n" + str + "\r\n");
} catch (IOException e) {
throw new RuntimeExcep