javaGUI图形大小写转换

有会的吗,键盘输入大写,点按钮,转换为小写。反之小写转换为大写


import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class 大小写转换 extends JFrame implements ActionListener{
    
    
    JTextField txtStr; //文本框
    
    //注册,关闭
    JButton btnSupper,btnLower; //按钮
    
    public 大小写转换() {
        
        super("大小写转换");
        
        txtStr = new JTextField(20); //默认显示的字符数
        add(txtStr);
        
        
        btnSupper = new JButton("转换为大写");
        btnLower = new JButton("转换为小写");
        //注册按钮事件
        btnSupper.addActionListener(this);
        btnLower.addActionListener(this);
        JPanel bottomPane = new JPanel(new FlowLayout(FlowLayout.CENTER));
        bottomPane.add(btnSupper);
        bottomPane.add(btnLower);
        add(bottomPane,BorderLayout.SOUTH);
        setSize(300,150);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
    }
    //Action事件
    @Override
    public void actionPerformed(ActionEvent e) {
        
        if(e.getSource() == btnSupper) {
            txtStr.setText(txtStr.getText().toUpperCase());
            
        }else if(e.getSource() == btnLower) {

            txtStr.setText(txtStr.getText().toLowerCase());
        }
    }
    public static void main(String[] args) {
        new 大小写转换();
    }
}

img

通过ASCII码的值来进行+或-32