Zooki Technologies Logo
Home Products Support

Java Component Development

EventInitializer
Overview
Description
System Requirements
Free Download
License Agreement

EventInitializer 1.0

Overview

Replace all your trivial anonymous inner classes used for event handling with a single call to EventInitializer.addEventListeners(this) for each container. This reduces the amount of code and time taken to implement event handling and reduces the download size of your AWT or Swing applications.

 

Description

The following code shows a typical way to handle events without EventInitializer. A trivial anonymous inner class is created to implement each required event listener for each component; this class simply calls another method to actually handle the event. In a typical application, this results in lots of unnecessary classes being implemented.

    private JButton button1 = new JButton("Button 1");
    private JButton button2 = new JButton("Button 2");

    public void initUI() {
        add(button1);
        add(button2);

        button1.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  button1_actionPerformed(e);
              }
        });

        button2.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  button2_actionPerformed(e);
              }
        });
    }

    private void button1_actionPerformed(ActionEvent e) {
         // code to do something when button1 is clicked.
    }

    private void button2_actionPerformed(ActionEvent e) {
         // code to do something when button2 is clicked.
    }

    

By using EventInitializer, you can replace all the code used to create the anonymous inner classes and add them to the components, with a single call to the addEventListeners method as follows:

    private void JButton button1 = new JButton("Button 1");
    private void JButton button2 = new JButton("Button 2");

    public void initUI() {
          add(button1);
          add(button2);
          EventInitializer.addEventListeners(this);
    }

    private void button1_actionPerformed(ActionEvent e) {
         // code to do something when button1 is clicked.
    }

    private void button2_actionPerformed(ActionEvent e) {
         // code to do something when button2 is clicked.
    }
    

The names of handler methods for events on the container have the format:
    this_method
where method is the name of an EventListener method.

The names of handler methods for events on a component have the format:
    component_method
where component is the identifier of the component field in the container and method is the name of an EventListener method.

Handler methods are expected to take a single parameter which is a subclass of EventObject.

 

System Requirements

EventInitializer requires JDK 1.3 or above due to use of Dynamic Proxy Classes.

 

Free Download

To use EventInitializer, please download event_1_0.zip. After downloading, extract the zip file using your preferred unzip utility. To unzip using the JDK jar tool, type: jar -xvf event_1_0.zip. The zip file contains the following:

  • event.jar - Jar file containing the EventInitializer classes
  • api - directory containing the API documentation for EventInitializer
  • src/com/zookitec/event - directory containing the Java source code for EventInitializer
  • src/EventDemo.java - source code for an example class that uses EventInitializer
  • license.txt - the license agreement (as below)
  • readme.txt - further instructions

 

License Agreement

This license agreement is based on the BSD license template at www.opensource.org/licenses/bsd-license.html

Copyright (c) 2001 Zooki Technologies. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name Zooki Technologies may not be used to endorse or promote products derived from this software without specific prior written permission. For written permission, please e-mail support@zookitec.com

THIS SOFTWARE IS PROVIDED BY ZOOKI TECHNOLOGIES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ZOOKI TECHNOLOGIES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 

Feedback Copyright © 2001 Zooki Technologies. All rights reserved.