Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Events

                         

In this section, you will learn how to handle events in Java awt. Events are the integral part of the java platform. You can see the concepts related to the event handling through the example and use methods through which you can implement the event driven application.

For any event to occur, the objects registers themselves as listeners. No event takes place if there is no listener i.e. nothing happens when an event takes place if there is no listener. No matter how many listeners there are, each and every listener is capable of processing an event. For example, a SimpleButtonEvent applet registers itself as the listener for the button's action events that creates a Button instance.

ActionListener can be implemented by any Class including Applet. One point to remember here is that all the listeners are always notified. Moreover, you can also call AWTEvent.consume() method whenever you don't want an event to be processed further. There is another method which is used by a listener to check for the consumption. The method is isConsumed() method. The processing of the events gets stopped with the consumption of the events by the system once a listener is notified. Consumption only works for InputEvent and its subclasses. Moreover, if you don't want any input from the user through keyboard then you can use consume() method for the KeyEvent. 

The step by step procedure of Event handling is as follow:

  1. When anything interesting happens then the subclasses of AWTEvent are generated by the component.
  2. Any class can act like a Listener class permitted by the Event sources. For example, addActionListener() method is used for any action to be performed, where Action is the event type. There is another method by which you can remove the listener class which is removeXXXListener() method, where XXX is the event type. 
  3. A listener type has to be implemented for an event handling such as ActionListener.
  4. There are some special type of listener types as well for which you need to implement multiple methods like key Events. There are three methods which are required to be implemented for Key events and to register them i.e. one for key release, key typed and one for key press. There are some special classes as well which are known as adapters that are used to implement the listener interfaces and stub out all the methods. these adapter classes can be sub classed and and can override the necessary method. 

AWTEvent

Most of the times every event-type has Listener interface as Events subclass the AWTEvent class. However, PaintEvent and InputEvent don't have the Listener interface because only the paint() method can be overriden with PaintEvent etc.

Low-level Events

A low-level input or window operation is represented by the Low-level events. Types of Low-level events are mouse movement, window opening, a key press etc. For example, three events are generated by typing the letter 'A' on the Keyboard one for releasing, one for pressing, and one for typing. The different type of low-level events and operations that generate each event are show below in the form of a table.

 FocusEvent   Used for Getting/losing focus.
 MouseEvent   Used for entering, exiting, clicking, dragging, moving, pressing, or releasing.
 ContainerEvent   Used for Adding/removing component.
 KeyEvent   Used for releasing, pressing, or typing (both) a key.
 WindowEvent   Used for opening, deactivating, closing, Iconifying, deiconifying, really closed.
 ComponentEvent   Used for moving, resizing, hiding, showing.

Semantic Events

The interaction with GUI component is represented by the Semantic events like changing the text of a text field, selecting a button etcThe different events generated by different components is shown below.

 ItemEvent  Used for state changed.
 ActionEvent   Used for do the command.
 TextEvent   Used for text changed.
AdjustmentEvent   Used for value adjusted.

Event Sources

If a component is an event source for something then the same happens with its subclasses. The different event sources are represented by the following table.

 Low-Level Events
 Window   WindowListener
 Container   ContainerListener
 Component   ComponentListener
 FocusListener
 KeyListener
 MouseListener
 MouseMotionListener

 

 Semantic Events
  Scrollbar    AdjustmentListener
 TextArea
 TextField
  TextListener
 Button
 List
 MenuItem
 TextField 
 ActionListener
 Choice
 Checkbox
 Checkbox
 CheckboxMenuItem
 List 
 ItemListener

Event Listeners

Every
listener interface has at least one event type. Moreover, it also contains a method for each type of event the event class incorporates. For example as discussed earlier, the KeyListener has three methods, one for each type of event that the KeyEvent has: keyTyped(), keyPressed(), and keyReleased().

The Listener interfaces and their methods are as follow:

 Interface  Methods
 WindowListener   windowActivated(WindowEvent e)
 windowDeiconified(WindowEvent e)
 windowOpened(WindowEvent e)
 windowClosed(WindowEvent e) 
 windowClosing(WindowEvent e)
 windowIconified(WindowEvent e)
 windowDeactivated(WindowEvent e)
 ActionListener  actionPerformed(ActionEvent e)
 AdjustmentListener  adjustmentValueChanged(AdjustmentEvent e)
 MouseListener  mouseClicked(MouseEvent e)
 mouseEntered(MouseEvent e)
 mouseExited(MouseEvent e)
 mousePressed(MouseEvent e)
 mouseReleased(MouseEvent e)
 FocusListener  focusGained(FocusEvent e)
 focusLost(FocusEvent e)
 ItemListener  itemStateChanged(ItemEvent e)
 KeyListener  keyReleased(KeyEvent e)
 keyTyped(KeyEvent e)
   keyPressed(KeyEvent e)
 ComponentListener  componentHidden(ComponentEvent e)
 componentMoved(ComponentEvent e)
 componentShown(ComponentEvent e)
 componentResized(ComponentEvent e)
 MouseMotionListener  mouseMoved(MouseEvent e)
   mouseDragged(MouseEvent e)
 TextListener  textValueChanged(TextEvent e)
 ContainerListen er  componentAdded(ContainerEvent e)
   componentRemoved(ContainerEvent e)

                                                         

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

I have designed a jsp page .
There are some itemstatechange event and button action perform .
i would like to call itemstatechange inside the button action perform.

please solve the problem.

Posted by Subhasis ballav on Friday, 10.3.08 @ 12:01pm | #80859

Latest Searches:
drill down using jfree
scroll bar
jstl list size
File InputStream
Struts Projects
helloe world servlet
dialog box alignment
pdf conversion from js
Jasper Reports
birthday
reading file(java)
iterator
java code to divide wi
tree
Photoshop Basic Shapes
generate report in exc
ั?à¹???ะà¸?ะà¸?à
remove rectangle
Vector
jsp with strutsframewo
select a row in jsp
code for running appl
login authentication
logout code in jsp
insert fields blob
foreach
OutStream wrapper Clas
decimals
ะà¸?ะ???ะà¸?ยÂ
text in a webbrowser u
JTable Renderer to be
jQuery To Hide the Div
Button
form action=
encapsulation
java strings
Installing Sun JDK on
real time in java
average numbers
set session servlet
ejp
Get first day of week
notes applet
fireTableCellUpdated
netbeans jsp jdbc
FlowLayout
breakаÐ?????аÐ????а
reading excel file usi
string trim/index.php?
hash map for loop
calculator code usind
Javascript Date and Ti
jsp bank examples
java: read string arra
Photoshop Photo Effect
requestDispatcher
HOWTO: Install Ruby on
combo box my sql
check character
dojo debug
capture screen j2me
how to create war file
struts2 gwt
Flash Special Effects
Create table and inser
struts 1 vs struts 2
bank application
java date compare exam
String to array in jav
Javascript Menus Image
Get Image
actionlistener
Using Select Statement
download file using js
J2ME Gauge
capture image j2me
Photoshop Write messag
flex struts
sum
Tracing in a multithre
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.