package yuzhengzhong;import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import javax.swing.JOptionPane;public class CodeTest { public static void main(String[] args){
   Frame frame=new Frame("余正忠的加解密软件");
   final TextField textOne=new TextField();
   final TextField textTwo=new TextField();
   final TextField textThree=new TextField();
   Button buttonOne=new Button("加密");
   Button buttonTwo=new Button("解密");
       
       frame.add(textOne,BorderLayout.NORTH);
       frame.add(textTwo,BorderLayout.CENTER);
       frame.add(textThree,BorderLayout.SOUTH);
       frame.add(buttonOne,BorderLayout.WEST);
       frame.add(buttonTwo,BorderLayout.EAST);
       
       buttonOne.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
      String str;
      String result = "";
      str=textOne.getText();
      if(str==null || str==""){
      String ooo="请输入要加密的文档";
      JOptionPane.showMessageDialog(null,ooo);
      return;
      }
      for(int i=0;i<str.length();i++){
      char c=str.charAt(i);
      c=(char)(c+10);
      result=result+c;
      }
      textTwo.setText(result);
        }
       });
       
       frame.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
        System.exit(1);
        }
       });
       
       frame.setSize(600,300);
       frame.setVisible(true);
       
   }
}
这里      if(str==null || str==""){
      String ooo="请输入要加密的文档";
      JOptionPane.showMessageDialog(null,ooo);
      return;
      }
判断文本框textOne的内容为空的话,就弹出对话框,然后退出按钮的事件处理,可是文本框为空,按下加密按钮,完全没反应,这是为啥?谢谢各位前辈的回答^ - ^