Java NetBeans GUI Key Event sending -
i'm making simple calculator, far did text field can type numbers , listens if key typed keyboard.
private void resultkeytyped(java.awt.event.keyevent evt) { }
what want click on let's '1' mouse , send key event method, clicked on keyboard. tried doing keypress robot says 'void type no here' or that. wanted run resultkeytyped method withing mouse click listener, this:
private void jbutton1mouseclicked(java.awt.event.mouseevent evt) { resultkeytyped(keyevent.vk_1); }
to call resultkeytyped
, have pass keyevent. can create keyevent using appropriate constructor:
keyevent event = new keyevent(textfield, 0, system.currenttimemillis(), 0, keyevent.vk_1); resultkeytypes(event);
although description (eg simple calculator
), sounds may wish choose different approach:
- add
actionlistener
jbutton
- within implementation of
actionlistener
, changejtextfield
text usingsettext
method
Comments
Post a Comment