Re: Swing and anonymous inner classes

Frank Meißner <[email protected]>
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Steven F. Toth wrote:
> A question to this forum, since you are mostly writing Swing Gui code.   
> Do you create many anonymous inner classes to handle events and  
> invokeLater calls?

First, I did just that. It is convenient if you have to write a few, 
*small* inner classes to get things done. But if things get bigger and 
more difficult, this is IMHO the wrong approach. Especially with swixml 
where having and not having a certain GUI element is only a matter of a 
(few) lines of XML-Code.

So my procedure is to write Action derivates to have them assigned to 
buttons, menus and the like. These actions are mostly on their own -- at 
least in respect to other actions. They do one job, nothing more, 
nothing less. If I want to get rid of an action, I just remove the 
defining class and remove the reference to it from the Xml. These Action 
classes are quite small and thus easy to maintain.

> And if so, do you think that having an easier way  
> to access methods via reflection would be a bonus?  So that instead of  
> having to create a new anonymous inner class for every little event  
> handler, you just have it redirect to a class method for example.

I'm aware this was only given as example but often the code really looks 
that way. I remember vividly a monster class with about 20 or 30 
doXxxx() methods doing just that. This monster was impossilbe to 
maintain and every developer was afraid to do so ;). So we split this 
thing up into the several (20 to 30) action classes after we removed the 
dependencies to the outer class by isolating code. A relief, I might tell...

Just my 2 Cent...

Frank

-- 
AuthentiDate International AG
Großenbaumer Weg 6
40472 Düsseldorf / Germany
Phone   : +49(0)211 43 69 89-0
FAX     : +49(0)211 43 69 89-19

TÜV Akademie
Kosten senken durch IT-Sicherheit
12.-13. Nov. 2003, Köln

IT Sicherheit in Chemie-
und Pharma-Unternehmen
25. Nov. 2003, Düsseldorf


Erfahren Sie mehr unter:
www.authentidate.de
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.