我这里有这段代码,它经过 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
最佳答案
您可以使用 HTML 来格式化消息:
JOptionPane.showMessageDialog(
null,
"<html><body><p style='width: 200px;'>LARGE ERROR MESSAGE HERE</p></body></html>");
关于java - 使用 JOptionPane 在代码末尾添加一条长消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56028663/