Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

KeyStroke  RSS feed

 
Javix Protocol
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been finding to get shortcuts on the menu items by using the KeyStroke class, and i am unable to get the thing done,
can anyone help me??
I also want to know whether using Mnemonic is better than KeyStroke class or what??
Please guide me..
:-)
------------------
Write Once , Run Anytime ,Anywhere Forever And Smile Happily.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set up a KeyListener and Listen for KeyEvents, when the desired combination of keys is pressed, you can do stuff between "key pressed" and "key released".
If you go to the API:
http://java.sun.com/products/jdk/1.3/docs/api/index.html
Look at the KeyListener Class, in "see also" it will direct you to a tutorial on setting this up.
 
Javix Protocol
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Cindy
Yeah i went through the API and trapped these events.Thanks for the help.
Can i mail u and clear my doubts from now on??
With regards..
JP
---------------------------------------------------------------
Originally posted by Cindy Glass:
If you set up a KeyListener and Listen for KeyEvents, when the desired combination of keys is pressed, you can do stuff between "key pressed" and "key released".
If you go to the API:
http://java.sun.com/products/jdk/1.3/docs/api/index.html
Look at the KeyListener Class, in "see also" it will direct you to a tutorial on setting this up.


------------------
Write Once , Run Anytime ,Anywhere Forever And Smile Happily.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although Cindy may be willing to answer email questions, it would be much more helpful to everyone if questions are asked and answered here, in public. Remember that for every person who asks a question there are hundreds who read the answer.
Wouldn't you have been happier if, when you came here, you found that someone had already answered your question?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Frank, I completely agree. I do NOT want to do e-mail answers. No benefit to the community.
BTW
myMenu.setMnemonic( 'F' ) ;
is the EASIEST way to set a simple shortcut as Stephanie points out here: http://www.javaranch.com/ubb/Forum2/HTML/000833.html
The KeyEvent way is only if you want to do fancy stuff also.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!