java - First key event jumps over the process -
i have been trying find info on bug, couldn't find relevant past several hours.
i'm using key event handling method in controller class. onkeypressed lies in fxml file, on root borderpane. main class standard.
this method part of calculator app, extracts char keycode , passes other method.
and problem is, seen during debugging, on first key press doesn't try generate string returned, jumps straight end of method. other keys pressed processed normally.
if printf before last curly brace, it's printed on console on first key press only.
here problem method:
public void handlekeys() { container.setonkeypressed(key -> { string returned = key.getcode().tostring().tolowercase(); char chr = '0'; switch (returned) { case "add": chr = '+'; break; default: if (character.tostring(returned.charat(returned.length() - 1)).matches("\\d") && returned.charat(returned.length() - 2) != 'f') { chr = returned.charat(returned.length() - 1); break; } } handlesymbols(chr); }); }
from understand, on first key press setonkeypressed method initialized , skips following code. think should somehow forward process last curly brace key -> { part. how?
if you're registering handler in fxml, presumably (you didn't post code) like
<borderpane fx:id="container" onkeypressed="#handlekeys" ... >
then handler registered: don't need register again in controller code. method specify invoked when event occurs. need method implement functionality need:
public void handlekeys(keyevent key) { string returned = key.getcode().tostring().tolowercase(); char chr = '0'; switch (returned) { case "add": chr = '+'; break; default: if (character.tostring(returned.charat(returned.length() - 1)).matches("\\d") && returned.charat(returned.length() - 2) != 'f') { chr = returned.charat(returned.length() - 1); break; } } handlesymbols(chr); }
Comments
Post a Comment