可能有什么异常没有捕获。把源码贴出来可能才有人知道。

解决方案 »

  1.   

    //这就是那个负责侦听的线程类;
    class Getdata implements Runnable{
    Thread t;
    Applet1 app;
    public Getdata(Applet1 a){
    app=a;
    t=new Thread(this);
    t.start();
    }
    public void run(){try{

    boolean more=true;
    while(more)
      {
    DatagramSocket socket=null;
    DatagramPacket packet=null;

    socket=new DatagramSocket(2222);
    byte[] buf=new byte[1024];

    packet=new DatagramPacket(buf,buf.length);
    socket.receive(packet);

    String str=new String(packet.getData());
    int n=Integer.parseInt(str.substring(0,1));
    app.label1.setText(n+"");             //
    app.in_color.setValue(app.color[n]);  //
    app.setBackground(Color.green);       //
    socket.close(); }

    }
    catch(Exception ee){app.label1.setText(ee.toString());}
    }