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:

  1. add actionlistener jbutton
  2. within implementation of actionlistener, change jtextfield text using settext method

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -