기본값이 null
이므로 null
을 적절하게 비교할 수 없으므로 JFrame
을 열 때 발생하는 포커스 이벤트는 속성 변경 이벤트를 발생시킵니다. 가능한 해결 방법에 대한 자세한 내용은 아래 코드를 참조하십시오.
하나의 해결 방법 NPE를 제거 할 수는 JFrame
가 열릴 때 PropertyChange
이벤트가 발생하지 않습니다 그 일 이후 PropertyChangeListener
를 추가하기 전에 fpsField
에 기본 값을 설정하는 것입니다. 기본 값을 설정할 수없는 경우
JFormattedTextField fpsField = new JFormattedTextField(NumberFormat.getInstance());
fpsField.setValue(0);
또 다른 해결책은, 이벤트의 이전 및 새 값이 delayField
를 업데이트하기 전에 실제로 다른 경우 확인하는 것입니다. 그들은 JFrame
이 열릴 때 null
입니다.
해고되는 이벤트는 이유 firePC
이 true
때문에
/**
* Processes any focus events, such as
* <code>FocusEvent.FOCUS_GAINED</code> or
* <code>FocusEvent.FOCUS_LOST</code>.
*
* @param e the <code>FocusEvent</code>
* @see FocusEvent
*/
protected void processFocusEvent(FocusEvent e) {
super.processFocusEvent(e);
// ignore temporary focus event
if (e.isTemporary()) {
return;
}
if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
InputContext ic = getInputContext();
if (focusLostHandler == null) {
focusLostHandler = new FocusLostHandler();
}
// if there is a composed text, process it first
if ((ic != null) && composedTextExists) {
ic.endComposition();
EventQueue.invokeLater(focusLostHandler);
} else {
focusLostHandler.run();
}
}
else if (!isEdited()) {
// reformat
setValue(getValue(), true, true);
}
}
및
/**
* Does the setting of the value. If <code>createFormat</code> is true,
* this will also obtain a new <code>AbstractFormatter</code> from the
* current factory. The property change event will be fired if
* <code>firePC</code> is true.
*/
private void setValue(Object value, boolean createFormat, boolean firePC) {
를 호출 원인이 ACTIVATION
이 JFormattedTextField
에 의해 해고 처리하는 FocusEvent
, 때문에, value
에 PropertyChange
이벤트가 발생합니다. 기본값은 null
때문에
마지막으로, 조건은 실제로 이벤트
/**
* Support for reporting bound property changes for Object properties.
* This method can be called when a bound property has changed and it will
* send the appropriate PropertyChangeEvent to any registered
* PropertyChangeListeners.
*
* @param propertyName the property whose value has changed
* @param oldValue the property's previous value
* @param newValue the property's new value
*/
protected void firePropertyChange(String propertyName,
Object oldValue, Object newValue) {
PropertyChangeSupport changeSupport;
synchronized (getObjectLock()) {
changeSupport = this.changeSupport;
}
if (changeSupport == null ||
(oldValue != null && newValue != null && oldValue.equals(newValue))) {
return;
}
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
을 발사합니다
, oldValue
및 newValue
모두 null
인에게 발사합니다.
문서화는 값 집합이 실제 값과 관련이없는'String' 형식으로 어떻게 구성되는지에 관한 것입니다. 짝수 전에 값을 설정하면 예외가 발생하기 때문에 null 값을 확인하기 만하면됩니다. 나는이 문제에 대해 더 많이 묻습니다. 왜냐하면 나는 그 문제를 해결할 수 없기 때문에가 아니라, 무엇이 일어나고 싶어 하는지를 이해하지 못하기 때문입니다. – Fr33dan
마지막으로 이벤트의 전체 체인을 발견했습니다. –
나는 점심에 가서 주제에 대한 에세이로 돌아왔다. 인상적인 작품. – Fr33dan