⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientpoint.java

📁 socket线程处理,进行多线成处理程序。
💻 JAVA
字号:
package hall;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.awt.*;

/**-----------------------------------
* <br>功能概述:客户端程序
------------------------------------*/
public class ClientPoint extends JFrame {
  //指定服务器套接口的地址和绑定端口号
  static int SERVERPORT = 8088;
  static String SERVERADDRESS = "192.168.202.141";
  
  //界面编程部分
  private JPanel jPanel1 = new JPanel();
  private JTextField jTextSendInfo = new JTextField(25);
  private JTextField jTextGetInfo = new JTextField(25);
  private JButton jSendButton = new JButton("发送");
  private JButton jClsButton = new JButton("清除");

  public ClientPoint(){
     super("客户端应用程序");
     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
     setSize(300,120);
     jPanel1.add(jTextSendInfo);
     jPanel1.add(jTextGetInfo);
     jTextGetInfo.setEditable(false);
     jPanel1.add(jSendButton);
     jPanel1.add(jClsButton);
     jSendButton.addActionListener(new ActionListener() {
      		public void actionPerformed(ActionEvent e) {
        		//发送信息,并获得反馈信息进行显示
        		MessageOperate();
      		}
    	});
    jClsButton.addActionListener(new ActionListener() {
      		public void actionPerformed(ActionEvent e) {
        		jTextSendInfo.setText("");
        		jTextGetInfo.setText("");
      		}
    	});
     this.setContentPane(jPanel1);
 }//ClientPoint()
 
  /**-----------------------------------
  * <br>功能概述:实现发送信息,获得反馈信息进行显示
  ------------------------------------*/
  public void MessageOperate(){
  	try{
	Socket client = new Socket(SERVERADDRESS,SERVERPORT);   
	//接收消息流对象
	BufferedReader brSocketReader = new BufferedReader(
		new InputStreamReader( client.getInputStream()));
	//发送消息流对象
	PrintWriter pwSocketWriter = new PrintWriter(
	      	new OutputStreamWriter(client.getOutputStream()),true);
	//发送jTextSendInfo消息
	pwSocketWriter.println(jTextSendInfo.getText());
	//获得反馈信息       
 	String strGetMSG = brSocketReader.readLine();
 	//显示反馈信息
 	jTextGetInfo.setText(strGetMSG);
 	brSocketReader.close();
 	pwSocketWriter.close();
 	client.close();
 	}
 	catch(Exception e){
 		e.printStackTrace();
 	}
  }//MessageOperate()
  
  /**-----------------------------------
  * <br>功能概述:实现窗口关闭
  ------------------------------------*/
  protected void processWindowEvent(WindowEvent e) {
      if (e.getID() == WindowEvent.WINDOW_CLOSING) {
     		//程序关闭
     		System.exit(0);
      }
      super.processWindowEvent(e);
  }//processWindowEvent()
  
  public static void main(String[] args) {
    	ClientPoint cp = new ClientPoint();
 	cp.show();
  }//main()
}/** ClientPoint */

⌨️ 快捷键说明

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