Thursday, February 11, 2010

Keyboard Java Key How Do I Assign A Key On The Keyboard To A Button In Java?

How do i assign a key on the keyboard to a button in java? - keyboard java key

I am solving a simulator in Java for a school project and I want the enter key or "calculate" ideas?

3 comments:

Tops said...

It is a tool to redefine all the buttons to help you.

Key Customizer is a software to change any key on the keyboard to other keys or buttons that you can not disable itself. Key Customizer This is not only a tool to customize your keyboard. With it you can guarantee your common 102-key change to a single multifunctional
http://www.keycustomizer.com/

elteano said...

There are two ways that I will go different ways, you think:

1) With the javax.swing.JButton class, and use the int (setMnemonic), the key mnemonic key, which is almost what you want to define. However, this requires that combines the look and feel Mouseless switch (obviously the old is usually the link below comes from).
For further information provided on this route, look http://java.sun.com/javase/6/docs/api/ and do a Ctrl + F for JButton (provided you use Windows, do not know the combination you have something else but it is) probably similar. Alternatively, you can search AbstractButton, where we still at the end. Then do a search to find setMnemonic that a large number is increasing by aParameters, then read the data.

2) Implement the interface and replacement java.awt.event.KeyListener keyPressed (KeyEvent e), insert the code block
if (e.getKeyCode KeyCode.VK_ == / * [key to associate the button with] * /) (
button.doClick ();
)
In the Enter key, you should VK_ENTER
Just in case you do not already know, application interface KeyListener without your abstract class, which requires the replacement of the following methods:
public void keyTyped (KeyEvent e)
void (MouseEvent e)
public void keyReleased (KeyEvent e)

The second is guaranteed to work, provided you want a unique key with the button instead of a combination that would be a little bit, but is connectednot too complicated. The first, of course, a little less code for their area, unless you make a unique key is the key difference mouseless also want to send the associated key somewhere, they probably do not want to go. For your purposes, the second is probably the right way.

Mouly G said...

try to use the Java class KeyStroke
to help U

Post a Comment