资源简介
使用GUI和TCP网络编程,实现图形界面化客户端给服务器发送消息,并附带登陆注册功能

代码片段和文件信息
package org.westos.Client;
import java.awt.*;
import java.awt.event.*;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
public class Client{
/**
* 客户端
*/
Socket socket=null;
public Client() {
/**
* 一、创建窗体
*/
//1.创建窗体
frame frame = new frame(“客户端“);
//2.设置窗体布局
frame.setLayout(null);
frame.setBounds(200 200 500 400);
frame.setLocation(700300);
frame.setResizable(false);
//3.创建文本域、设置文本域背景色、设置文本域字体颜色
TextArea textArea = new TextArea();
textArea.setBounds(20 30 470 280);
textArea.setEditable(false);
textArea.setBackground(Color.DARK_GRAY);
textArea.setForeground(Color.white);
//4.创建文本框,用来输入
TextField textField = new TextField();
textField.setBounds(20 320 470 30);
//4.创建发送、退出按钮
Button button = new Button(“SEND“);
button.setBackground(Color.gray);
button.setBounds(340 360 50 30);
Button button1 = new Button(“EXIT“);
button1.setBackground(Color.gray);
button1.setBounds(440 360 50 30);
//6.将文本域、文本框和按钮加入到窗体里
frame.add(textArea);
frame.add(textField);
frame.add(button);
frame.add(button1);
//7.显示窗体
frame.setVisible(true);
//8.给窗体添加关闭事件
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//9.给退出按钮添加事件
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
/**
* 二、发送数据并显示在文本域中
*/
//1.与服务端建立连接,设置服务端ip和端口
try {
socket = new Socket(“127.0.0.1“9999);
} catch (IOException e) {
e.printStackTrace();
}
//2.在文本域textAree中提示一句话
textArea.append(“请输入你要发送的数据:\r\n“);
//3.给发送按钮添加事件,每点击一次button按钮(SEND)触发一次
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//3.1获取文本狂textField中的数据
String text = textField.getText();
//3.2将文本框textField中输入的内容,添加到文本域textAree中
textArea.append(text+“\r\n“);
//3.3再将文本框置空
textField.setText(null);
//3.4获取通道中的流
OutputStream outputStream = null;
try {
outputStream = socket.getOutputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
//3.5包装流
DataOutputStream
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-05-31 14:57 聊天室小项目\
目录 0 2019-05-31 14:57 聊天室小项目\.idea\
目录 0 2019-05-31 14:57 聊天室小项目\.idea\artifacts\
文件 312 2019-05-29 13:13 聊天室小项目\.idea\artifacts\Client_jar.xm
文件 312 2019-05-29 13:13 聊天室小项目\.idea\artifacts\Server_jar.xm
目录 0 2019-05-31 14:57 聊天室小项目\.idea\dictionaries\
文件 87 2019-05-29 19:16 聊天室小项目\.idea\dictionaries\.xm
文件 258 2019-05-28 20:21 聊天室小项目\.idea\encodings.xm
文件 278 2019-05-28 19:58 聊天室小项目\.idea\misc.xm
文件 575 2019-05-30 13:20 聊天室小项目\.idea\modules.xm
文件 18305 2019-05-30 16:14 聊天室小项目\.idea\workspace.xm
目录 0 2019-05-31 14:57 聊天室小项目\out\
目录 0 2019-05-31 14:57 聊天室小项目\out\artifacts\
目录 0 2019-05-31 14:57 聊天室小项目\out\artifacts\Client_jar\
文件 13026 2019-05-29 21:14 聊天室小项目\out\artifacts\Client_jar\客户端Client.jar
目录 0 2019-05-31 14:57 聊天室小项目\out\artifacts\Server_jar\
文件 3221 2019-05-29 21:14 聊天室小项目\out\artifacts\Server_jar\服务端Server.jar
目录 0 2019-05-31 14:57 聊天室小项目\out\production\
目录 0 2019-05-31 14:57 聊天室小项目\out\production\客户端Client\
目录 0 2019-05-31 14:57 聊天室小项目\out\production\客户端Client\me
文件 65 2019-05-29 21:13 聊天室小项目\out\production\客户端Client\me
目录 0 2019-05-31 14:57 聊天室小项目\out\production\客户端Client\org\
目录 0 2019-05-31 14:57 聊天室小项目\out\production\客户端Client\org\westos\
目录 0 2019-05-31 14:57 聊天室小项目\out\production\客户端Client\org\westos\Client\
文件 693 2019-05-29 19:47 聊天室小项目\out\production\客户端Client\org\westos\Client\Client$1.class
文件 720 2019-05-29 19:47 聊天室小项目\out\production\客户端Client\org\westos\Client\Client$2.class
文件 1861 2019-05-29 19:47 聊天室小项目\out\production\客户端Client\org\westos\Client\Client$3.class
文件 2251 2019-05-29 19:47 聊天室小项目\out\production\客户端Client\org\westos\Client\Client.class
文件 687 2019-05-30 16:06 聊天室小项目\out\production\客户端Client\org\westos\Client\Login$1.class
文件 2655 2019-05-30 16:06 聊天室小项目\out\production\客户端Client\org\westos\Client\Login$2.class
文件 711 2019-05-30 16:06 聊天室小项目\out\production\客户端Client\org\westos\Client\Login$3.class
............此处省略36个文件信息
相关资源
- Modbus协议官方文档中、英文全
- SpringBoot+H2+mybatis-plus59130
- 登录注册界面.zip48872
- Omron ETN21模块进行modbustcp通讯
- 数字华容道
- SSM+Shiro+redis实现单点登陆
- jstl-api-1.2和jstl-impl-1.2
- 嵌入式图形界面MiniGUI的示例程序9例
- 基于MVC模式的会员管理系统
- STM32基于rt_thread操作系统的SDHC卡文件
- 国内一家大型软件公司内部的正规软
- 仿windows记事本
- GUI银行管理系统
- STM32F103RBT6驱动UC1698控制芯片的160160黑
- 组态王中S7-300TCP驱动
- 超市收银系统eclipse access大学课程设计
- 基于Apache Mina实现的TCP长连接和短连接
- 模拟ATM柜员机系统--连接数据库
- CVI下的TCP服务器和客户端
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
- TCP 发包工具(windows)
- A*算法的2D演示(带源码)
- 代码审查表和代码审查实例
- VxWorks TCPIP协议栈
- socket小工具(可方便建立TCP UDP的soc
- vc 编写的基于TCP协议的客户/服务器
- 仿126 网易 163 邮箱 界面
- Tomcat6.x
- 基于CSocket的多人聊天室
- 简单的行编辑器
评论
共有 条评论