Java Question - Mnemonics (or something similar)

Discussion in 'OT Technology' started by AngstyWhiteBoy, Jan 19, 2007.

  1. AngstyWhiteBoy

    AngstyWhiteBoy Desperately seeking purpose

    Joined:
    Aug 31, 2004
    Messages:
    6,801
    Likes Received:
    0
    Location:
    Dallas, TX
    For my OOP class I have to make a simple calculator program in java. It was easy except for one minor thing:

    I want to make it so that when I press the 1 button on the keyboard, it acts as if I had used the mouse to click on the 1 JButton. Same thing with the enter key and the "=" sign. I know how to use mnemonics, and I've set it up so that if I do alt+1, it will work, but that really isn't what I want to do. I've looked all over the place and haven't been able to find anything.
     
  2. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    I haven't used mnemonics in a while in Java so I can't remember if you can set it up to use keys without pressing the Alt key with it. What you can do instead is set up a key listener and when someone presses a key that matches what you have on your calculator, have the listener call the doClick() method on the appropriate JButton.
     

Share This Page