Java实现 Unicode字符查询器

package TestJText;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CJText extends JFrame {
    Box boxH, boxV1, boxV2,boxV3;
    public CJText(){
        init();
        setTitle("Unicode字符查询器");
        setBounds(100, 100, 400, 100);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());
        getContentPane().setBackground(Color.cyan);
        setVisible(true);
    }
    void init() {
        boxV2 = Box.createVerticalBox();
        boxV3 = Box.createVerticalBox();
        boxH = Box.createHorizontalBox();
        JPanel jPanel = new JPanel();
        jPanel.setLayout(new GridLayout(2,1,10,10));
        jPanel.setBackground(Color.cyan);
        JLabel jLabel = new JLabel("           字符");
        JLabel jLabel1 = new JLabel("Unicode码");
        JTextField jTextField = new JTextField(10);
        JTextField jTextField1 = new JTextField(10);
        JButton button = new JButton("查询Unicode码");
        JButton button1 = new JButton("查询字符");
        jPanel.add(jLabel);
        jPanel.add(jLabel1);
        add(jPanel);
        boxV2.add(jTextField);
        boxV2.add(jTextField1);
        boxV3.add(button);
        boxV3.add(button1);
        boxH.add(Box.createHorizontalStrut(10));
        boxH.add(boxV2);
        boxH.add(boxV3);
        this.add(boxH);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (jTextField.getText().length() == 0) {
                    jTextField.setText("<值为空重新输入>");
                    return;
                }
                char c = jTextField.getText().charAt(0);//得到第一个字符
                jTextField1.setText("" + (int) c);//输出字符的Unicode码
            }
        });
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(jTextField1.getText().length()==0)
                    return;
                jTextField.setText(""+(char)Integer.parseInt(jTextField1.getText()));//将数字转化为Unicode码对应的字符
            }
        });
    }
}

package TestJText;

public class CJTextTest {
    public static void main(String[] args) {
        new CJText();
    }
}

运行结果 :

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中的Unicode字符流是指一种能够完整处理Unicode字符的输入输出流。在Java中,Unicode字符是以16位无符号整数表示的字符,范围从'\u0000'到'\uFFFF'。而Unicode字符流是一种能够读取和写入Unicode字符的流。 在Java中,我们可以使用InputStream和OutputStream分别创建Unicode字符的输入流和输出流。Unicode字符输入流能够从外部数据源(如文件或网络连接)读取Unicode字符,而Unicode字符输出流则能够将Unicode字符写入到目标数据源中。 Java提供了一系列Unicode字符流的实现类,如InputStreamReader和OutputStreamWriter。这些类可以将普通的字节流转换为Unicode字符流,以方便我们对Unicode字符进行读写操作。 使用Unicode字符流的好处是它们能够避免由于字符编码问题而导致的数据损坏或读取错误。Unicode字符流能够正确地处理各种语言字符集,包括中文、日文、韩文等。 使用Unicode字符流的步骤如下: 1. 创建一个InputStreamReader对象,它将连接到一个字节流。 2. 通过InputStreamReader对象提供的方法,可以逐个读取Unicode字符。 3. 创建一个OutputStreamWriter对象,它将连接到一个字节流。 4. 通过OutputStreamWriter对象提供的方法,可以逐个写入Unicode字符。 总之,Java中的Unicode字符流是一种能够处理Unicode字符的输入输出流。使用Unicode字符流可以确保对Unicode字符的正确读写,避免字符编码引起的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值