Java Reference
In-Depth Information
width: 250
height: 80
scene: scene = Scene {
content: Group {
content: [
Rectangle {
width: bind scene.width
height: bind scene.height
fill: Color.LIGHTBLUE
onKeyTyped: function(e:KeyEvent):Void {
if(java.lang.Character.isLetterOrDigit(
e.char.charAt(0)) or
java.lang.Character.isWhitespace(
e.char.charAt(0)) ) {
text.content = "{text.content}{ e.char }";
}
}
onKeyReleased: function(e:KeyEvent):Void {
if( e.code == KeyCode.VK_BACK_SPACE ) {
text.content = text.content.substring(
0, text.content.length()-1);
}
}
},
text = Text {
// center text in scene
translateX: bind
(scene.width - text.layoutBounds.width)/2 -
text.layoutBounds.minX;
translateY: bind
(scene.height - text.layoutBounds.height)/2 -
text.layoutBounds.minY;
font : Font {size : 24}
textOrigin: TextOrigin.TOP
fill: Color.NAVY
}
]
}
}
}
Another way to handle the backspace key is to look at the key event char directly.
if(java.lang.Character.isLetterOrDigit(
e.char.charAt(0)) or
java.lang.Character.isWhitespace(
e.char.charAt(0)) ) {
Search WWH ::




Custom Search