Knute Johnson wrote:
So I could have checked the JTextField reference against all the others
in the array and gotten an index that way but that didn't sound a whole
lot better than the way I was getting it now.
As a matter of general design, avoid maintaining more than one independent copy
of the same information unless there's a good reason to do so (normally some
sort of performance and/or robustness consideration). That's rather a
fundamental design principle, and applies to all software (and other systems,
come to that).
In this case you have the information about the index of each element stored in
two places: as part of the structure of the array (you could find the index
with a loop); and in the instance field of the (otherwise unnecessary, I
presume) subclass of JTextField. That won't cause a lot of damage in this
particular case (especially if the indexes never change), but it's rather a
baroque arrangement all the same, and as you gain more experience as a designer
you will learn to avoid such constructions where possible.
-- chris