Archive for August 23rd, 2008

Since Java 1.1, the recommended and standard way of event handling in a GUI component is through registering event listener. There are two types of event listener. One is the standard listener that are inherited in all component due to inheritance and the another is those specific to the UI type (eg Windows)

For example, the common types of event listener prevalent in all subclass of component include

  • ComponentListener
  • FocusListener
  • MouseListener

For those who want to understand more about event model of Java, do read http://mindprod.com/jgloss/event11.html

The use of event listener together with anonymous inner class greatly simplify event handling because registering of event listeners is just as easy as removing them through a series of add/remove event listener method defined in the component.

JFrame _fra = new JFrame(“Testing”);

_fra.addWindowListener(new WindowAdapter()



On the other hand,  as much as it make it easy to handle event, it make it troublesome to disable them especially event listener is registered throughout the component in various class. Each class may need to add method to enable/disable the event listener. There are likely multiple classes registering the same event in a component and all of sudden enable and disable them become involving and time-consuming. So what is the feasible solution to this situation ? The answer is to control and to use the centralized base class event methods that fire the specific event. By controlling these methods, it will be easy to enable/disable event firing even though the component might be registered with a specific event all over the classes.



Read Full Post »