Home arrow Java & J2EE arrow Page 2 - Event Handling In Java Part II

Explicit-Event Handling - Java

With the skills that you have developed so far from Part I of the tutorial, you can design a graphical user interface with beauty and easy. Let us refresh ourselves before we proceed, Events are method calls that Javas windowing system performs whenever any element of a user interface is manipulated.

TABLE OF CONTENTS:
  1. Event Handling In Java Part II
  2. Explicit-Event Handling
  3. Open The Window And Inhale Java In The Air
  4. Easy Steps For Coding
  5. A Glimpse Of Adapters In Java
  6. Preparing to Launch Our Java Applet And Handle Events
By: Gayathri Gokul
Rating: starstarstarstarstar / 23
September 15, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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 & J2EE Articles          >>> More By Gayathri Gokul
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: