client3.java

来自「该原代码为<Java编程基础、应用与实例>的附盘代码」· Java 代码 · 共 46 行

JAVA
46
字号
import java.awt.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
public class Client3 extends Frame{
  private TextArea msgView=new TextArea();
  private TextField sendBox=new TextField();
  private DataInputStream reader;
  private DataOutputStream writer;
  Socket socket;
  public Client3(String title){
    super(title);
    msgView.setEditable(false);
    add(msgView,"Center");
    add(sendBox,"South");
    sendBox.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        try{
          writer.writeUTF(sendBox.getText());
          writer.flush();
          String fileInfo=reader.readUTF();
          msgView.setText("< " + sendBox.getText()+"狼 郴侩 >\n\n");
          msgView.append(fileInfo);
          sendBox.setText("");
        }catch(Exception ie){}
      }
    });
    pack();
  }
  private void connect(){
    try{
      msgView.append("辑滚家南苞狼 楷搬阑 矫档钦聪促.\n");
      socket=new Socket("127.0.0.1", 7777);
      msgView.append("楷搬 肯丰... 焊绊酵篮 颇老狼 捞抚阑 涝仿窍技夸.\n");
      reader=new DataInputStream(socket.getInputStream());
      writer=new DataOutputStream(socket.getOutputStream());
    }catch(Exception e){
      msgView.append("楷搬 角菩..");
    }
  }
  public static void main(String[] args){
    Client3 client=new Client3("辑滚 矫胶袍 颇老 焊扁");
    client.setVisible(true);
    client.connect();
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?