eXtropia: the open web technology company
Technology | Support | Tutorials | Development | About Us | Users | Contact Us
Resources
 ::   Tutorials
 ::   Presentations
Perl & CGI tutorials
 ::   Intro to Perl/CGI and HTML Forms
 ::   Intro to Windows Perl
 ::   Intro to Perl 5
 ::   Intro to Perl
 ::   Intro to Perl Taint mode
 ::   Sherlock Holmes and the Case of the Broken CGI Script
 ::   Writing COM Components in Perl

Java tutorials
 ::   Intro to Java
 ::   Cross Browser Java

Misc technical tutorials
 ::   Intro to The Web Application Development Environment
 ::   Introduction to XML
 ::   Intro to Web Design
 ::   Intro to Web Security
 ::   Databases for Web Developers
 ::   UNIX for Web Developers
 ::   Intro to Adobe Photoshop
 ::   Web Programming 101
 ::   Introduction to Microsoft DNA

Misc non-technical tutorials
 ::   Misc Technopreneurship Docs
 ::   What is a Webmaster?
 ::   What is the open source business model?
 ::   Technical writing
 ::   Small and mid-sized businesses on the Web

Offsite tutorials
 ::   ISAPI Perl Primer
 ::   Serving up web server basics
 ::   Introduction to Java (Parts 1 and 2) in Slovak

 

Introduction to Web Programming
JDK 1.0 Event Handling  
  • For instance, in our OK button example, when the button generates an action event, its own handleEvent() method is first called with the action event information.

  • Therefore, we can subclass the button and implement a handleEvent() routine to look for action events. Consider the following example:

    class MyButton extends Button
    {
    public boolean handleEvent(Event event)
      {
      if (event.id == Event.ACTION_EVENT)
        System.out.println("I got an action: " +
                           event);
        return super.handleEvent(event);
      }
    }
    

  • In this case, we simply create a subclass of Button which prints out a note whenever it is pressed.

Notice that we called super.handleEvent() in the last line of code in our handleEvent() implementation. It's very important to do this, since this passes the event to the button's superclass (in this case Button) to allow it the option of also handling events.

The superclass of MyButton is Button--the button class itself. The Button class listens for mouse up and down events in its handleEvent() routine. When a mouse up and down occurs in the button, the Button posts an action event. If we didn't call super.handleEvent() in our MyButton class, the Button class's handleEvent() method would never get called and would never know that the mouse had been pressed and released. Since it wouldn't get called, it would never generate an action event. So, our MyButton class would never receive an action event, since one would never be generated.

That's why its important to call super.handleEvent() at the end of a handleEvent() implementation. You need to make sure the object's superclasses also process the event. In this case, if we didn't call super.handleEvent(), the button wouldn't respond to anything at all since our routine would be catching all the events and never sending them on to its superclass.

Some books state that you should return true in your handleEvent() method if you are handling the event yourself and don't want to pass on the event to other possibly interested parties. However, we would simply suggest you always call super.handleEvent() to pass the event on to the class's superclass as well as other possibly interested parties.

Previous Page | Next Page