Saturday, 22 February 2014

EVENT CLASSES:The KeyEvent Class

KeyEvent and MouseEvent are subclasses of abstract InputEvent class .............


The KeyEvent class


                 A KeyEvent is gnerated when the keyboard input occurs.This low-level event is generated by a component object (such as a text field) when a key is pressed, released, or typed. The event is passed to every KeyListener or KeyAdapter object which registered to receive such events using the component's addKeyListener method.

Integer constants:


CHAR_UNDEFINED:
KEY_PRESSED and KEY_RELEASED events which do not map to a  valid Unicode character use this for the keyChar value.

KEY_FIRST:
               The first number in the range of ids used for key events.
KEY_LAST:
             The last number in the range of ids used for key events.

KEY_PRESSED:
          The "key pressed" event.


KEY_RELEASED:
         The "key released" event.

KEY_TYPED:
            The "key typed" event.

 VK_0 to VK_9 :
            VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39).

VK_A to VK_Z:  
              VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A).

VK_ENTER,VK_ESCAPE,VK_CANCEL,VK_UP,VK_DOWN,VK_LEFT,VK_RIGHT,
VK_PAGE_DOWN,VK_PAGE_UP,VK_ALT,VK_SHIFT,VK_CONTROL:   
   The vk constant spaecify virtual key codes and are independent of any maodifiers,  such as control,shiftor alt.

KeyEvent 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)

             Here,src is a reference to the component that generated the event.The type of Event is specified by the type.The system time at which the key was pressed is passed in when.modifiers arguments indicates which modifier were pressed when this key event occurred. The character equivalent is passed in ch.If no valid character exists,then ch contain CHAR_UNDEFINED.

KeyEvent METHODS:


  • getKeyChar():

                which reurns the character that was entered.
                syntax
              char getkeyChar()


  • getKeyCode()

               which return the key code.
              syntax
                      int getKeyCode()

No comments:

Post a Comment