import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.swing.*;

class MyFrame extends JFrame {
    JTextField ip;
    JTextField port;
    JTextField tex;
    JTextArea content;
    JButton connect;
    JButton say;
    Socket Clientsocket;
    MyFrame(){
        setLayout(new FlowLayout()); //设置窗体为流式布局
        setSize(500,480);
        setLocation(800,100);
        add(new JLabel("Server:ip"));
        ip=new JTextField("127.0.0.1",8);
        add(ip);
        add(new JLabel("Server:port"));
        port=new JTextField("8888",8);
        add(port);
        connect=new JButton("connect");
        add(connect);
        content=new JTextArea(16,50);
        JScrollPane scroll=new JScrollPane(content); //设置滚动条
        add(scroll);
        add(new Label("Say:"));
        tex=new JTextField("Hello,this is client.",25);
        add(tex);
        say=new JButton("say");
        add(say);
        ConnectListener ConnectListener=new ConnectListener();
        SayListener SayListener = new SayListener();
        connect.addActionListener(ConnectListener); //注册监听器
        say.addActionListener(SayListener); //注册监听器
    }


    class ConnectListener implements ActionListener{
        int portNum;
        public void actionPerformed(ActionEvent e){
            connect.setEnabled(false); //按下 connect 按钮后， connect 不可再次点击
            try {
                content.setText("Connect to server....\n"); //在文本区中显示 "Connect to server....\n"
                portNum =Integer.parseInt(port.getText()); //读取 port 文本框中的字符串，并将字符串转化为整型赋给 portNum
                Clientsocket = new Socket(ip.getText(),portNum); //定义对象 socket，并指定主机号和端口号 portNum
                ClientThread ct = new ClientThread(); //定义一个 ClientThread 类的对象 ct
                ct.start(); //启动线程，并调用ClientThread 类中的 run（）方法
            } catch (IOException x) {
                content.append("Disconnected to server...");
                System.out.println(x);
            }
        }
    }
    class SayListener implements ActionListener{
        String str;
        public void actionPerformed(ActionEvent e){
            try {
                PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(Clientsocket.getOutputStream())),true); //从 socket 获取字节输出流，并将其最终转化为 PrintWriter
                str=tex.getText(); //从文本框中获取字符串赋给 str
                if(!str.isEmpty()){
                    out.println(new Date()+ "\n"+ str); //打印日期和 str
                    content.append(new Date()+"\n Me:"+str+"\n");
                    out.flush(); //清空缓存区
                }
                tex.setText("");
            } catch (Exception x) {
                System.out.println(x);}
        }
    }
    class ClientThread extends Thread{
        public void run(){
            try {
                InputStreamReader isr=new InputStreamReader(Clientsocket.getInputStream());
                BufferedReader br=new BufferedReader(isr );//创建一个缓冲输出流，其形参为从套接字 socket 中获取的输入流
                //BufferedReader in = new BufferedReader(new InputStreamReader(Clientsocket.getInputStream())); //创建一个缓冲输出流，其形参为从套接字 socket 中获取的输入流
                String str=null;
                while(true){
                    str = br.readLine(); //按行读取
                    content.append( str+"\n");
                }
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }
}

public class Main{
    public static void main(String[] args) {
        MyFrame client=new MyFrame();
        client.setTitle("网络通信客户端");
        client.setVisible(true);
        client.setResizable(false); //设置此窗体是否可由用户调整大小
        client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置关闭操作
    }
}请详细分析改代码的构建过程及思路