java GUI编程时创建UDP套接字的问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 19:31:43
我想实现按下链接按钮服务器端就能自动创建DatagramSocket和DatagramPacket,服务器端此部分代码如下:
//链接按钮事件监听类
private class ConnectListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{

try
{
GameServer=new DatagramSocket(1314);
msgarea.setFont(TextFont);
msgarea.setForeground(Color.BLUE);
msgarea.setText("服务器套接字创建成功");

}
catch(SocketException e1)
{
msgarea.setFont(TextFont);
msgarea.setForeground(Color.CYAN);
msgarea.setText("服务器套接字创建失败");
}
catch(SecurityException e2)
{
msgarea.setFont(TextFont);
msgarea.setForeground(Color.black);
msgarea.setText("权限错误");
}

Gamebuff1=new byte[250];
Gamebuff2=new byte[250];
Gamepacket2=new DatagramPacket(Gamebuff2,Gamebuff2.length);

try
{
GameServer.receive(Gamepacket2);
msgarea.setFont(TextFont);
msgarea.setForegrou

jButton6.addMouseListener(new usi_jButton6_mouseAdapter(this));

还以为是按钮的问题,

最后才发现没添加事件监听器!

我原来就碰到过一个超郁闷的问题!