import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JText_test extends JFrame implements ActionListener {
      JTextField inputtext = new JTextField();
      JTextField resulttext = new JTextField();
      public JText_test() {
         try {
            jbInit();
         }catch (Exception exception) {
            exception.printStackTrace();
         }
      }
      private void jbInit() throws Exception {
          getContentPane().setLayout(null);
          inputtext.setText("输入英文");
          inputtext.setBounds(new Rectangle(22, 32, 132, 30));
          inputtext.addActionListener(this);   //将JText_test2类的实例作为监视器
          this.setTitle("事件处理");
          this.getContentPane().add(resulttext);
          this.getContentPane().add(inputtext);
          resulttext.setText("结果");
          resulttext.setBounds(new Rectangle(23, 91, 134, 29));
       }
       public static void main(String args[]) {
          JText_test tx = new JText_test();
          tx.setBounds(200, 200, 200, 200);
          tx.validate();
          tx.setVisible(true);
       }
       public void actionPerformed(ActionEvent e) {      //事件处理语句
           String word = inputtext.getText();
           if (word.equals("boy")) {
               resulttext.setText("男孩");
           } 
           else if (word.equals("girl")) {
               resulttext.setText("女孩");
           } 
           else if (word.equals("sun")) {
               resulttext.setText("太阳");
           } 
           else {
               resulttext.setText("没有该单词");
           }
       }
}

