编程是MyEclipse总会出现warning,实际项目时允许出现么?
还是要一个一个地优化,消灭warning?

解决方案 »

  1.   

    客户端
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    class liaot extends Frame
    {
    Socket socket=null;
    private TextArea text1;
    private TextField text2;
    //图形界面
    liaot(){
    text1 = new TextArea();
    text2 = new TextField();
    add(text1,"Center");
    add(text2,"South");
    try{
    socket = new Socket("192.168.30.129",3334);
    }catch(Exception ee){}
    event();
    setBounds(300,300,300,300);
    setVisible(true);

    }
    //事件响应
    public void event(){
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });
    text2.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){


    // new Thread(new clientsend()).start();
    new Thread(new clientrec()).start();
    send();
    //rece();
    text2.setText("");
    }
    });
    } public static void main(String[] args)throws Exception 
    {
    new liaot();
    }
    //发送
    public void send(){
    byte[]buf = text2.getText().trim().getBytes();
    String str = new String(buf,0,buf.length);
    System.out.println(str);
    // text1.setText(str+text2.getText()+"\r\n");
    try{
    DataOutputStream dos = new DataOutputStream(socket.getOutputStream());

    dos.writeUTF(str);
    dos.flush();
    // out.write("\r\n".getBytes());
    ;
    }catch(Exception e){}
    }

    class clientsend implements Runnable
    {
    public void run(){
    send();
    }
    }
    //接收
    public void rece(){
    try{
    DataInputStream dis = new DataInputStream(socket.getInputStream());
    String str = dis.readUTF();

    text1.append(str+"\r\n");
    }catch(Exception e){}
    }
    class clientrec implements Runnable
    {
    public void run(){
    // byte[] buf = new byte[1024];
    rece();

    }
    }
    }
    服务端
    import java.io.*;
    import java.net.*;
    import java.util.*;
    class liaotserver 
    {
    static List<server> list = new ArrayList<server>();
    public static void main(String[] args)throws Exception 
    {
    Socket socket;
    ServerSocket ss = new ServerSocket(3334);
    while(true){
    socket = ss.accept();
    System.out.println("hahahah....");
    server ser = new server(socket);
    list.add(ser);
    new Thread(ser).start();
    }
    }
    static class server implements Runnable
    {
    private DataOutputStream dos;
    private DataInputStream dis;
    private Socket socket = null;
    server(Socket socket){
    this.socket = socket;
    try{
    dos = new DataOutputStream(socket.getOutputStream());
    dis = new DataInputStream(socket.getInputStream());
    }catch(Exception e){}
    }
    public void send(String str){
    try{
    //System.out.println(str);
    dos.writeUTF(str);
    dos.flush();

    }catch(Exception e){}
    }
    public void run(){
    // byte[] buf = new byte[1024];
    try{
    while(true){
    String str = dis.readUTF();

    //System.out.println(str);
    for(int i=0;i<list.size();i++){
    server s = list.get(i);
    s.send(str);
    }
    }
    }catch(Exception e){}

    }
    }}
    我运行一个客户端时,运行正常,显示结果正常,运行两个客户端时,我在第一个客户端写“你好”,第一个客户端能显示“你好”,但是第二个客户端不能显示,但是我要是在第二个客户端写上“哈哈”,”哈哈“不能显示,而是第一个客户端的”你好“显示出来了,每次输入都是这样,什么原因啊,怎么改?
      

  2.   

    对,让自己的代码完美,使其尽量不存在warning