|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.KeyStroke
A KeyStroke instance represents a key being typed on the keyboard -- it contains both a char code for the key and a modifier (alt, shift, ctrl, meta, or a combination).
KeyStroke objects are used to define high-level (semantic) action events. Instead of trapping every keystroke and throwing away the ones you are not interested in, those keystrokes you care about automatically initiate actions on the components they are registered with.
KeyStroke objects handle both character-code generating keystrokes you would trap with a KeyTyped event handler and key-code generating keystrokes (like Enter or F1) that you would trap with a KeyPressed event handler.
KeyStroke objects are immutable and unique.
All KeyStroke objects are cached. To get one, use getKeyStroke
.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.
JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)
,
getKeyStroke(char)
, Serialized FormMethod Summary | |
boolean |
equals(Object anObject)
Returns true if this object is identical to the specified object. |
char |
getKeyChar()
Returns the character defined by this KeyStroke object. |
int |
getKeyCode()
Returns the numeric keycode defined by this KeyStroke object. |
static KeyStroke |
getKeyStroke(char keyChar)
Return a shared instance of a key stroke that is activated when the key is pressed (i.e. |
static KeyStroke |
getKeyStroke(char keyChar,
boolean onKeyRelease)
Deprecated. use getKeyStroke(char) |
static KeyStroke |
getKeyStroke(int keyCode,
int modifiers)
Return a shared instance of a key stroke given a char code and a set of modifiers -- the key is activated when it is pressed. |
static KeyStroke |
getKeyStroke(int keyCode,
int modifiers,
boolean onKeyRelease)
Return a shared instance of a key stroke given a numeric keycode and a set of modifiers, specifying whether the key is activated when it is pressed or released. |
static KeyStroke |
getKeyStroke(String s)
Parse a string with the following syntax and return an a KeyStroke: |
static KeyStroke |
getKeyStrokeForEvent(KeyEvent anEvent)
Return a keystroke from an event. |
int |
getModifiers()
Returns the modifier keys defined by this KeyStroke object. |
int |
hashCode()
Returns a numeric value for this object that is likely to be reasonably unique, so it can be used as the index value in a Hashtable. |
boolean |
isOnKeyRelease()
Returns true if this keystroke is active on key release. |
String |
toString()
Returns a string that displays and identifies this object's properties. |
Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Method Detail |
public static KeyStroke getKeyStroke(char keyChar)
keyChar
- the character value for a keyboard keypublic static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease)
keyChar
- the character value for a keyboard keyonKeyRelease
- a boolean value. When true, specifies that
the key is active when it is released.public static KeyStroke getKeyStroke(int keyCode, int modifiers, boolean onKeyRelease)
The "virtual key" constants defined in java.awt.event.KeyEvent can be used to specify the key code. For example:
keyCode
- an int specifying the numeric code for a keyboard keymodifiers
- an int specifying any combination of the key modifiers.onKeyRelease
- a boolean value. When true, specifies that
the key is active when it is released.KeyEvent
,
Event
public static KeyStroke getKeyStroke(int keyCode, int modifiers)
The "virtual key" constants defined in java.awt.event.KeyEvent can be used to specify the key code. For example:
keyCode
- an int specifying the numeric code for a keyboard keymodifiers
- an int specifying any combination of the key modifiers.KeyEvent
public static KeyStroke getKeyStrokeForEvent(KeyEvent anEvent)
This method obtains the keyChar from a KeyTyped event, and the keyCode from a KeyPressed or KeyReleased event, so you the type of event doesn't matter.
anEvent
- the KeyEvent to obtain the KeyStroke frompublic static KeyStroke getKeyStroke(String s)
"<modifiers>* <key>" modifiers := shift | control | meta | alt | button1 | button2 | button3 key := KeyEvent keycode name, i.e. the name following "VK_".Here are some examples:
"INSERT" => new KeyStroke(0, KeyEvent.VK_INSERT); "control DELETE" => new KeyStroke(InputEvent.CTRL_MASK, KeyEvent.VK_DELETE); "alt shift X" => new KeyStroke(InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, KeyEvent.VK_X);
public char getKeyChar()
getKeyStroke(char)
public int getKeyCode()
getKeyStroke(int,int)
public int getModifiers()
getKeyStroke(int,int)
public boolean isOnKeyRelease()
getKeyStroke(int,int,boolean)
public int hashCode()
Hashtable
public boolean equals(Object anObject)
anObject
- the Object to compare this object topublic String toString()
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |