KeyEvent Class Assignment Help

Assignment Help: >> Controls and Events - KeyEvent Class

KeyEvent Class:

A KeyEvent is produce when keyboard input occurs.  There are three types of key events, that are identified through these integer constants: KEY_PRESSED, KEY_RELEASSED, and KEY_TYPED. The first two events are produced, when any key is pressed or released. A last event occurs only when a character is produced.

There are several other integer constants which are defined through KeyEvent. For instance, VK_0 through VK_9 and VK_A through VK_Z define the ASCII equal of the nubers and letters. Here are a few others:

VK_ENTER               VK_ESCAPE             VK_CANCEL                       VK_UP

VK_DOWN               VK_LEFT                  VK_RIGHT               VK_PAGE_DOWN

VK_PAGE_UP          VK_SHIFT                 VK_ALT                    VK_CONTROL

The VK Constants specify vitrual key codes and are independent of any modifiers, like as control, shift, or alt. KeyEvent is a subclass of InputEvent and has these two constructors:

KeyEvent(Component src,int type,long when,int modifiers,int code)

 KeyEvent(Component src,int type,long when,int modifiers,int code,char ch)

Above, src is a reference to the component which produced the event.  A type of the event is specified through type.  The system time at that the key was pressed is passed in when.  The modifiers argument denotes that modifiers were pressed when this key event occurred.  A virtual key code, like as VK_UP, VK_A, and so forth, is passed in code.   A character equivalent (if one exists) is passed in ch. ch contains CHAR_UNDEFINED if no valid character exists. For KEY_TYPED events, code will hold VK_UNDEFINED.

The KeyEvent class declares various methods, but the most general used ones are getKeyChar(),that returns the character that was entered, and getKeyCode() ,that returns the key code. Their common forms are display here:

Char getKeyChar() Int getKeyCode()

getKeyChar() returns CHAR_UNDEFINED if no valid character is available. When a KEY_TYPED event occurs, getKeyCode() returns VK_UNDEFINED.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd