Java
  Home arrow Java arrow Page 2 - Event Handling In Java Part II
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVA

Event Handling In Java Part II
By: Gayathri Gokul
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2003-09-15


    Table of Contents:
  • Event Handling In Java Part II
  • Explicit-Event Handling
  • Open The Window And Inhale Java In The Air
  • Easy Steps For Coding
  • A Glimpse Of Adapters In Java
  • Preparing to Launch Our Java Applet And Handle Events

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Event Handling In Java Part II - Explicit-Event Handling
    ( Page 2 of 6 )

    An alternate way to handle events is to sub class the components and override the method that receives and dispatches event. For example you can drive a class from Button class and override the processActionEvent() method. The default action of the processActionEvent() method is to dispatch the event to the event listeners.

    Example1:
    Class OKButton extends Button
    {
           Public OKButton (String caption)
           {
               super(caption);
               //enable processing of action events
                enableEvents(AWTEvent.Action_Event_Mask);
             }
    
             Public void processActionEvent(ActionEvent e)
              {
                   // process event, and call superclass method 
    			   // as it calls actionPerformed() method
                      super.processActionEvent(action);
             }
    }
    
    A subclass can act as an event listener for itself as shown in the following code:
    Class OKButton extends Button implements ActionListener
    {
       Public OKButton(String caption)
       {
               super(caption);
               //add an action listener to the button
                 addActionListener(this);
        }
        Public void actionPerformed(ActionEvent ae)
       {
             // code to process event
        }
    }
    


     
     
    >>> More Java Articles          >>> More By Gayathri Gokul
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek