Java 使用JOptionPane在代码末尾添加一条长消息
我这里有一段代码,它通过Java 使用JOptionPane在代码末尾添加一条长消息,java,joptionpane,Java,Joptionpane,我这里有一段代码,它通过ArrayList检查添加的客户信息是否符合程序的标准。我已经完成了所有这些工作,我的问题是如何在代码末尾打印一条JOptionPane消息,显示一条消息中的每个错误,而不是在每次检查后打印多条JOptionPane消息。如果输入不等于if语句,我希望所有这些单独的消息都在最后的一条大消息中 for(Customer c : customerCopy){ //checking is username entered equals a userna
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
for(客户c:customerCopy){
//检查输入的用户名是否等于文件中已有的用户名
如果(c.getUserName().equals(userTextStr))
sameUserName=true;
if(sameUserName)
showMessageDialog(null,“用户名已被使用”);
}
//检查输入的两个密码是否相互匹配
如果(!passStr.equals(passStr2))
showMessageDialog(null,“密码不匹配”);
//检查密码长度是否在有效范围内
如果(密码长度()<8 | |密码长度()>10)
showMessageDialog(null,“密码无效长度”);
布尔值大写=!passStr.equals(passStr.toLowerCase());
boolean hasLowerCase=!passStr.equals(passStr.toUpperCase());
布尔hasInteger=false;
对于(int i=0;i
您可以使用HTML格式化邮件:
JOptionPane.showMessageDialog(
null,
"<html><body><p style='width: 200px;'>LARGE ERROR MESSAGE HERE</p></body></html>");
JOptionPane.showMessageDialog(
无效的
“此处出现较大错误消息
”;
您可以使用HTML格式化邮件:
JOptionPane.showMessageDialog(
null,
"<html><body><p style='width: 200px;'>LARGE ERROR MESSAGE HERE</p></body></html>");
JOptionPane.showMessageDialog(
无效的
“此处出现较大错误消息
”;