在输入时,我的文本字段开始删除输入并抛出java.io.EOFException。在我的keyReleased
事件处理程序中,count
仍为0
;处理程序没有执行count++
。
有人可以建议我做错了什么以及如何解决这个问题?
public void keyReleased(KeyEvent e) {
int count = 0;
result = null;
setVisible(false);
matchingVector.clear();
String searchTerm = dialog.getField(getSearchFieldNumber());
System.out.println(searchTerm);
if (searchTerm.length() > 0) {
listModel.removeAllElements();
System.out.println(recordVector.size());
for (int i = 0; i < recordVector.size(); i++) {
if (matchesCriteria(recordVector.get(i), searchTerm)) {
matchingVector.add(recordVector.get(i));
count++;
}
}
if (count == 0) {
clearFields();
System.out.println("Bad-bad things happen here?");
} else if (count == 1) {
updateFields(matchingVector.get(0));
} else if (count > 1) {
validate();
setVisible(true);
setSize(WIDTH, Math.min(500, matchingVector.size() * ROW_HEIGHT));
}
} else {
clearFields();
}
}
答案 0 :(得分:0)
你错过了matchesCriteria
中其他人的左括号
以下代码应该起作用private boolean matchesCriteria(Record record, String searchTerm){
Booking booking = (Booking) record;
if(booking.className.toLowerCase().contains(searchTerm.toLowerCase())){
listModel.addElement(booking.className);
return true;}
else{return false;}
}