While preparing a presentation for my local JUG, I copied the code from the
TextBox Javadoc and I was surprised that I could type a "." (period) in the
TextBox. Looking closer at the API for the KeyboardListener, it seems that
the example code uses a keyCode where it should be using a charCode.
public void onKeyPress(Widget sender, char keyCode, int modifiers) {
if ((!Character.isDigit(keyCode)) && (keyCode != (char) KEY_TAB)
&& (keyCode != (char) KEY_BACKSPACE)
&& (keyCode != (char) KEY_DELETE) && (keyCode != (char) KEY_ENTER)
&& (keyCode != (char) KEY_HOME) && (keyCode != (char) KEY_END)
&& (keyCode != (char) KEY_LEFT) && (keyCode != (char) KEY_UP)
&& (keyCode != (char) KEY_RIGHT) && (keyCode != (char) KEY_DOWN)) {
// TextBox.cancelKey() suppresses the current keyboard event.
((TextBox)sender).cancelKey();
}
void *onKeyPress*(Widget
<http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/Widget.html>
sender,
char keyCode,
int modifiers)
Fired when a keyboard action generates a *character
*As KEY_DELETE = 46 and the character value for '.' = 46, the demo code
allows typing '.' in the textbox. The onKeyPress method should be using
chars and the onKeyUp and onKeyDown should use keyCodes (dependent on the
keyboard configuration). I think it would be better to change the API
definition to onKeyPress(Widget sender, char keyChar, int modifiers) to
avoid the confusion. Additionally, I don't think onKeyPress ever gets the
navigation or special keys (DELETE, BACKSPACE, UP, DOWN, etc...)
Cheers,
Fred
*
*
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---