>>> I am added listeners (DocumentListener) to a GUI component
>>> (specifically a class that extends JTextField). I am wondernig why
>>> listeners can be instantiated WITHOUT knowing any of the information
>>> within the listener. For example...
>> Your anonymous class inherits a reference to the instance of the
>> surrounding class. Your method commonUpdate() are invoked on that
>> instance; same for fields ("nameTextField" in this case).
> Is there any particular reason you would/would not want to do this?
> (For example, the reason I did it this way is because every text field
> reacts somewhat differently depending on the field.
Some people (including me) find the code rather unreadable.
Arne
Jason Cavett - 12 Jun 2007 19:17 GMT
On Jun 11, 8:31 pm, Arne Vajh?j <a...@vajhoej.dk> wrote:
> >>> I am added listeners (DocumentListener) to a GUI component
> >>> (specifically a class that extends JTextField). I am wondernig why
[quoted text clipped - 10 lines]
>
> Arne
Yeah. That's my biggest complaint. But, honestly, I'm not sure of a
better way to go about it. I mean, given the fact that something
different is done based on each text field, button, etc it seems like
I could either:
A. Create a ton of specific classes for each item.
B. Do it inline.
C. ???
If there's another way, I'd be open to hearing it. Listeners have
always given me problems from an OO perspective.
Arne Vajhøj - 13 Jun 2007 04:30 GMT
>>>>> I am added listeners (DocumentListener) to a GUI component
>>>>> (specifically a class that extends JTextField). I am wondernig why
[quoted text clipped - 18 lines]
> If there's another way, I'd be open to hearing it. Listeners have
> always given me problems from an OO perspective.
I am not aware of any brilliant solution.
I tend to prefer passing this to all and then have
the actionPerformed test for source.
Arne