import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CaseConverter extends JFrame {
private JTextField inputField;
private JTextField outputField;
private JButton capitalButton;
private JButton lowercaseButton;
public CaseConverter() {
// 设置窗口标题
setTitle("Case Converter");
// 设置窗口布局为FlowLayout
setLayout(new FlowLayout());
// 创建组件
inputField = new JTextField(20);
outputField = new JTextField(20);
capitalButton = new JButton("Capital");
lowercaseButton = new JButton("Lowercase");
// 将组件添加到窗口中
add(inputField);
add(outputField);
add(capitalButton);
add(lowercaseButton);
// 向按钮添加按压事件监听器
capitalButton.addActionListener(new CapitalListener());
lowercaseButton.addActionListener(new LowercaseListener());
}
// 定义Capital按钮的按压事件监听器
private class CapitalListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// 从输入文本框中获取输入字符串
String input = inputField.getText();
// 将字符串中的大写字母转换为小写字母,其它字符不变
String output = input.toLowerCase();