21天养成好习惯_13

21天养成好习惯_第十三天

今天结束Java 的 GUI 编程的学习

先作个整体回顾
第一大类:AWT

可参考资料:Java GUI入门 AWT编程相关知识

  1. 组件和容器
  2. 布局管理器
  3. 事件监听
  4. 输入框TextField监听
  5. 综合实例: 简易计算器 源码: 简易计算器
  6. 画笔
  7. 窗口监听
  8. 键盘监听
第二大类 :Swing
  1. 窗口,面板
  2. 弹窗
  3. 标签
  4. 按钮
  5. 列表
  6. 文本框

本人是按照B站视频的狂神视频学习的

狂神的GUI编程

其他内容

C++ , 大学物理 , 数据库的相关知识

C++的函数:

  1. iota(array,array+n,num);
    给 数组array从array[0] ~ array[n] 赋值num(以1为步长递增赋值)
  2. itoa(num,str,10);
    num 为int str为char* 数组 (下同):把num转化为字符串 并传入str中
  3. sprintf(str,"%d",num); (这里只列举sprintf 的一种情况):
    讲num以十进制解释转化为字符串str中 ,并传入str中


    itoa函数的运行效率比sprintf高

代码测试效率实例

#include "coding.hpp"

int main(){
    std::cout << "starting" <<std::endl;

    int num = 100;
    char str[25];

    auto start = clock();
    for(int i = 0;i < 10000000; i++){
        sprintf(str,"%d",num);
    }
    auto end = clock();

    std::cout << (end - start) << std::endl;
    std::cout << "ending" << std::endl;
    //---------------------------------------    
    start = clock();
    for(int i = 0;i < 10000000; i++){
        itoa(num,str,10);
    }
    end = clock();
    std::cout << (end - start) << std::endl;

}

运行结果:

在这里插入图片描述

Java端口的一些小知识点

在这里插入图片描述

有用的一些bash命令

在这里插入图片描述

简单网络编程一些知识

一. 客户端

  1. 连接服务器Socket
  2. 发送数据

二. 服务端

  1. 建立服务的端口ServerSocket
  2. 等待用户的连接 accept
  3. 接收用户的数据

三 : 实例:

服务端的代码 : TCPServerDome.java

package Net_Study.Tcp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class TCPServerDome {
    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        Socket socket = null;
        InputStream is = null;
        ByteArrayOutputStream baos = null;

        try{
            //1.我得有一个地址
            serverSocket = new ServerSocket(9999);

            while(true){    //while循环 , 必须手动关闭程序
                //2.等待客户端连接进来
                socket = serverSocket.accept();
                //3.读取客户端的信息
                is = socket.getInputStream();

            /* //这种方法如果面对大数据可能会有bug
                    byte[] buffer = new byte[1024];
                    int len;
                    while((len = is.read(buffer)) != -1){
                        String msg = new String(buffer,0,len);
                        System.out.println(msg);
                    }
            */
                //利用管道流更优秀
                baos = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int len;
                while((len = is.read(buffer)) != -1){
                    baos.write(buffer,0,len);//先将内容写入完全后再输出
                }
                System.out.println(baos.toString());
            }



        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if(serverSocket != null){
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (socket != null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (is !=null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (baos != null){
                try {
                    baos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

客户端的代码: TCPClientDome.java

package Net_Study.Tcp;


import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

//客户端
public class TCPClientDome {
    public static void main(String[] args) {
        InetAddress serverIP = null;
        Socket socket = null;
        OutputStream os = null;

        try{
            //1.要知道服务器的地址,端口号
            serverIP = InetAddress.getByName("127.0.0.1");
            int port = 9999;
            //2.创建一个socket连接
            socket = new Socket(serverIP,port);
            //3.发送消息IO流
            os = socket.getOutputStream();
            os.write("你好,我是Client".getBytes(StandardCharsets.UTF_8));

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (os != null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (socket != null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }


        }
    }
}

运行结果:(注意要先运行服务端的代码 , 因为要先让服务端创建一个端口, 客户端才可以连接到这个端口)

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值