Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

java - 这是一个AWT程序,用于执行各种字符串操作,例如反向字符串,字符串大写/小写,长度(This is an AWT program to perform various string operations like reverse string, string uppercase/lowercase, length)

This is a Java AWT program to perform various string operations like reverse string, string uppercase/ lowercase, string length.

(这是一个Java AWT程序,用于执行各种字符串操作,例如反向字符串,字符串大写/小写,字符串长度。)

I have error

(我有错误)

invalid method declaration;

(方法声明无效;)

return type required

(需要返回类型)

import java.io.*;
import java.awt.*;
import java.awt.event.*;
class StringOperationsGUI extends Frame
{
    TextField tf1, tf2;
    public StringOperationsGUI()
    {
        setLayout(new FlowLayout());

        Label lb1=new Label("Enter String");
        Label lb2=new Label("Result is: ");

        tf1=new TextField(25);
        tf2=new TextField(25);

        Button btn1=new Button("Reverse");
        Button btn2=new Button("To Uppercase");
        Button btn3=new Button("To Lowecase");
        Button btn4=new Button("Length");

        add(lb1); add(tf1);
        add(lb2); add(tf2);
        add(btn1); add(btn2); add(btn3); add(btn4);

        btn1.addActionListener(new Inner1());
        btn2.addActionListener(new Inner2());
        btn3.addActionListener(new Inner3());
        btn4.addActionListener(new Inner4());
    }

    class Inner1 implements ActionListener
    {
        public static actionPerformed(ActionEvent ae)
        {
            StringBuffer sb=new StringBuffer(tf1.getText());
            tf2.setText(sb.reverse().toString());
        }
    }

    class Inner2 implements ActionListener
    {
        public static actionPerformed(ActionEvent ae)
        {
            String s=tf1.getText();
            tf2.setText(s.toUpperCase());
        }
    }

    class Inner3 implements ActionListener
    {
        public static actionPerformed(ActionEvent ae)
        {
            String s=tf1.getText();
            tf2.setText(s.toLowerCase());
        }
    }

    class Inner4 implements ActionListener
    {
        public static actionPerformed(ActionEvent ae)
        {
            String s=tf1.getText();
            tf2.setText(""+s.length());
        }
    }

    public static void main(String ar[])
    {
        StringOperationsGUI fr=new StringOperationsGUI();
        fr.setSize(300,300);
        fr.setTitle("Performing String Operations");
        fr.setVisible(true);
    }
}

My output shows this

(我的输出显示了这一点)

这就是在cmd提示符下显示的内容

  ask by Anonymous translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...