资源简介
使用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个文件信息
相关资源
- mybatis-plus 实践及架构原理
- Qt客户端和服务器传输图片、文本
- ONENET TCP透传脚本
- 在UniGUI中使用百度Echarts作为数据展示
- UGUI轮播功能基于DoTween
- 无私奉献Jscal2-1.7
- irun User Guide.pdf
- 学成在线项目最新,视频笔记源码最
- 基于MVC模式的扫雷游戏
- 山东大学操作系统nachos实验报告
- 山东大学操作系统nachos课程设计
- Ogre 3d 1.7 beginner Guide 源码
- 九章数据结构与算法视频.txt
- atguigu-Hadoop.txt
- MCGS_ModBusTCP样例
- 羽毛球馆信息管理系统
- TCP文件传输的设计与实现
- magicCubeModel
- 学生迎新管理系统
- Baidu链接 直接跳转至百度网页
- 零食商城,完整的,有购物车
- 职工管理系统
- KUKA和康耐视相机TCPIP通讯.pptx
- 日历js源代码
- 国密加密解密sm4完整版
- spring boot cloud实战租房网平台(视频和
- 操作系统页面置换模拟
- Qt多客户端聊天程序.zip
- 简单多客户端聊天GUI界面,服务器转
- 简单多客户端Tcp通信,服务器转发消
评论
共有 条评论