Listener Adder
The 1.1 event model is more flexible,
but arguably harder to use than the earlier model.
It encourages the use of anonymous classes as handlers,
rapidly increasing the number of classes in a directory.
An alternative coding style is to implement the Listener interfaces,
and add "this" as a listener on each control,
being careful to add each one,
and to add the proper type of listener for each.
That chore can be eliminated by using a
ListenerAdder.java
helper class,
which adds all relevant listeners for all components,
even if they are nested in Panels or Menus.
As this
ListenerDemo.java
coding example shows,
this lets you write less code.
You will also have less class files to manage,
and enjoy faster loading.
Most listener methods will employ an "if ladder"
to branch to code for the particular control that was used.
Some cynics might say this turns 1.1 into 1.0 code,
but that is not true ;-)
It captures the best of both,
the power of 1.1 and coding simplicity of the 1.0 model.
A similar technique is described in Chapter 3,
"Event Adapters,"
of the O'Reilly book,
"Developing Java Beans"
by Robert Englander.
A very nice book.
See
Developing Java Beans
for an FTP link to the Event Adapter code.
This software is provided free of charge with no support.
Email
me at morris_hirsch@brown.edu
if you do have a problem,
and I will try to help,
but I cannot promise to.
Your suggestions,
comments,
bug reports,
fixes,
are all welcome!
Was this Helpful?
Was this Helpful?
Was it what you were looking for?
How did you find this page?
Search result,
following a link,
recommendation?
Please let me know.
Email
me at morris_hirsch@brown.edu
Legalities
Except for all sections which are identified as the work,
and copyright,
of others,
this work is Copyright (C) 1998 by Morris Hirsch.
All rights reserved,
except as granted here.
Redistribution and use in source and binary forms,
with or without modification,
for any purpose,
are permitted,
except as may be restricted by original copyright holders,
provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice,
all earlier copyright notices of others,
this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice,
all earlier copyright notices of others,
this list of conditions and the following disclaimer,
in the documentation,
and/or other materials provided with the distribution.
DISCLAIMER
This software is provided free of charge with no support.
This software is provided in source format;
You are advised to examine it and understand it,
before putting it to use.
This software uses only algorithms and coding techniques
that are available to the public in the open literature.
You are however,
advised to make your own determination of legality,
for your intended use.
This software is provided by the Author and Contributors ``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 the Author or Contributors,
or their Agents,
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.
Other Java..
Please also visit my home page.