日期:2014-05-20  浏览次数:20754 次

为什么只能有第一个if语句的功能?后面的语句都没执行
/**

* 定义注册监听类

*/
public class RegistBtnActionListener implements ActionListener {
String userName = userNameJtf.getText();

String password = passwordJtf.getText();

String surePassword = surePasswordJtf.getText();

String email = emailJtf.getText();

public void actionPerformed(ActionEvent e){
if(userName.equals("")|password.equals("")|surePassword.equals("")|email.equals("")){
  //判断是否没有填写完整
  JOptionPane.showMessageDialog(null, "请将空白处填写完整", "提示信息", 2);
  }else if (!password.equals(surePassword)){
JOptionPane.showMessageDialog(null, "对不起,前后密码不一致!","提示信息",JOptionPane.ERROR_MESSAGE);
passwordJtf.setText("");
surePasswordJtf.setText("");
return;
} else if (!email
.matches("^([a-z0-9A-Z]+[-1\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$")) {
JOptionPane.showMessageDialog(null, "对不起,你的邮箱格式不合法!","提示信息",JOptionPane.ERROR_MESSAGE);
emailJtf.setText("");
return;
} else {
JFrameRegist jr=new JFrameRegist();
jr.registConnect("E:\\musicPlatform");
JOptionPane.showMessageDialog(null, "注册成功!","提示信息",1);
}


}
}

------解决方案--------------------
userName.equals("")|password.equals("")|surePassword.equals("")|email.equals(""))
------解决方案--------------------
或的判断用|而不是用||改成下面代码试试
Java code
 /**
     *
     * 定义注册监听类
     *
     */
    public class RegistBtnActionListener implements ActionListener {
        String userName = userNameJtf.getText();

        String password = passwordJtf.getText();

        String surePassword = surePasswordJtf.getText();

        String email = emailJtf.getText();

        public void actionPerformed(ActionEvent e){
            if(userName.equals("")||password.equals("")||surePassword.equals("")||email.equals("")){
                //判断是否没有填写完整
                JOptionPane.showMessageDialog(null, "请将空白处填写完整", "提示信息", 2);
            }else if (!password.equals(surePassword)){
                JOptionPane.showMessageDialog(null, "对不起,前后密码不一致!","提示信息",JOptionPane.ERROR_MESSAGE);
                passwordJtf.setText("");
                surePasswordJtf.setText("");
                return;
            } else if (!email
                    .matches("^([a-z0-9A-Z]+[-1\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$")) {
                JOptionPane.showMessageDialog(null, "对不起,你的邮箱格式不合法!","提示信息",JOptionPane.ERROR_MESSAGE);
                emailJtf.setText("");
                return;
            } else {
                JFrameRegist jr=new JFrameRegist();
                jr.registConnect("E:\\musicPlatform");
                JOptionPane.showMessageDialog(null, "注册成功!","提示信息",1);
            }


        }
    }