我一直在读这个:http://docs.oracle.com/javase/tutorial/uiswing/components/passwordfield.html,但我有一个问题。我有一个简单的方法来检查我的JTextField和JPasswordField是否为空
所以我有这个:
private boolean addCustomerCheckValidInfo()
{
for(JPasswordField pf : newCustomerPasswordFields)
{
if (pf.getPassword().length == 0);
{
System.out.println("Password length " + pf.getPassword().length);
return false;
}
}
return true;
}Password length 3正如我在oracle指南中所读到的,passfield.getPassword().length应该返回长度(就像它在system.print.out中所做的那样),但是当它大于0时,如果它等于0,它为什么会失败呢?
发布于 2013-05-20 01:43:08
if (pf.getPassword().length == 0);你打错了。您在if语句的末尾添加了一个";“。所以你真的创建了一个空的if语句。去掉";“。
https://stackoverflow.com/questions/16637483
复制相似问题