The components we create in general like button,radio,frame etc do not do anything on their own with respect to user input .To make a valid GUI ,we need to provide controls to these components. Providing controls to a component is done via GUI programming or Event Driven programming. Below are the events:
- Windows Events-Destroying, exposing,iconifying,deconifying and moving windows.
- Mouse Events-Moving the mouse,dragging a mouse,enter and exit from components,engage and release button of a mouse.
- Keyboard Events-pressing a key and releasing a key.
- List Events-Selecting and deselecting a list item.
- Scrolling Events:-Scrolling a line up or down. page up or down or scrolling to an exact location.
Object target;//the component that originally received the event. long when;//the time stamp of when the event occured. int id;//the type of the event int x;//the x coordinate of the event. int y;//the y coordinate of the event. int key;//the key that was passed in a keyboard event. int modifier;//the state of the modifier key(Shift,control,alt) int clickCount;//the number of consecutive clicks. Object arg;//an event dependent argument that helps to identify the event causing GUI events.(Label of a button)
Different event types possible are listed below:
|These events occurs when the corresponding activity is performed on a window object.|
|These are generated by mouse actions within the borders of canvas,Frame and Panel components|
|Generated as the mouse enters or exits the borders of canvas,Frame and Panel components.They
are also generated as we click a mouse in a Text,TextArea,List,Combo etc components.
|Generated by pressing or releasing keys on the keyboard when we are on the borders of canvas,Frame
and Panel components or inside a Text,TextArea,List,Combo etc components.
|Action Events||ACTION_EVENT||Generated when we click on a Button,choice or checkbox component,press enter in a TextFiled or double
click on a list item.
|Generated by actions involving the scrollbar in scrollbar component.|
The id variable in the Event class will be initiated by the corresponding event type during the automatic instantiation of the respective Event object. There are numbers of event handling methods declared in component class and Event class. The method handleEvent(Event evt) in component class is the central event dispatcher for a component.This method for a given event type(evt.id) calls the corresponding method.
|Event MOUSE_DOWN||mouseDown(Event e,int x,int y)|
|Event MOUSE_UP||mouseUp(Event e,int x,int y)|
|Event MOUSE_DRAG||mouseDrag(Event e,int x,int y)|
|Event MOUSE_ENTER||mouseEnter(Event e,int x,int y)|
|Event MOUSE_EXIT||mouseExit(Event e,int x,int y)|
|Event KEY_PRESS||keyDown(Event e,int key)|
|Event KEY_ACTION||keyDown(Event e,int key)|
|Event KEY_RELEASE||keyUp(Event e,int key)|
|Event KEY_ACTION_RELEASE||keyUp(Event e,int key)|
|Event LOST_FOCUS||lostFocus(Event e,Object o)|
|Event GOT_FOCUS||getFocus(Event e,Object o)|
|Event ACTION_EVENT||action(Event e,Object o)|
List and Scrollbar components do not have their helper functions.To handle these, it is required to override the handleEvent() method.