我这里有经过ArrayList<>
的这段代码,并检查添加的客户信息是否与该程序的条件匹配。我已完成所有工作,我的问题是如何在代码的末尾打印一条JOptionPane消息,从而在一条消息中显示每个错误,而不是在每次检查后都打印多个JOptionPane消息。如果输入不等于if
语句,我希望所有这些单独的消息都放在最后一个大消息中。
for(Customer c : customerCopy){
//checking is username entered equals a username already in the file
if(c.getUserName().equals(userTextStr))
sameUserName = true;
if(sameUserName)
JOptionPane.showMessageDialog(null, "User name already taken");
}
//checking if both passwords that are entered match each other
if(!passStr.equals(passStr2))
JOptionPane.showMessageDialog(null, "Passwords don't match");
//checking if the password length is within the valid range
if(passStr.length() < 8 || passStr.length() > 10)
JOptionPane.showMessageDialog(null, "Password invalid length");
boolean hasUpperCase = !passStr.equals(passStr.toLowerCase());
boolean hasLowerCase = !passStr.equals(passStr.toUpperCase());
boolean hasInteger = false;
for(int i = 0; i < passStr.length(); i++)
if(Character.isDigit(passStr.charAt(i)))
hasInteger = true;
//checking to see if password contains an uppercase letter
if(!hasUpperCase)
JOptionPane.showMessageDialog(null, "Password must contain an uppercase letter");
//checking to see if password contains a lowercase letter
if(!hasLowerCase)
JOptionPane.showMessageDialog(null, "Password must contain a lowercase letter");
//checking to see if the password contains a number
if(!hasInteger)
JOptionPane.showMessageDialog(null, "Password must contain a number");//PUT ONE LARGE ERROR MESSAGE AT THE END
答案 0 :(得分:0)
您可以使用HTML格式化消息:
JOptionPane.showMessageDialog(
null,
"<html><body><p style='width: 200px;'>LARGE ERROR MESSAGE HERE</p></body></html>");