Without analyzing deeply your code (a bit long...), I can answer 'yes' to your question: don't pass around indexes, it is indeed very brittle. Just pass the objects themselves, you will pass actually just references to these objects.
Don't do
x.add(new Item()) but do
Item item = new Item(); x.add(item); so you can pass the item to the next constructor.
Note 1: the cast on graphicalItems.get() isn't necessary (old habit? You omit it elsewhere).
Note 2:
for (int i = 0; i <= graphicalItems.size()-1; i++) is more usually written
for (int i = 0; i < graphicalItems.size(); i++). For a trained eye, the first form makes the mind to pause and think, while the second one is just glanced at once.
Note 3: When you don't need an index, the new for loop is handy:
- for (int i=0; i < adaptorTo.length; i++) {
- if (adaptorTo[i] != null) {
- adaptorTo[i].display ( this ) ;
- } // if
- } // for
can be:
- for (AdaptorType to : adaptorTo) {
- if (to != null) {
- to.display ( this ) ;
- } // if
- } // for
(why you don't use an array list here?)
or:
- for (int i = 0; i <= graphicalItems.size()-1; i++ ) {
- GraphicalItem myGraphicalItem1 = graphicalItems.get(i);
- if (myGraphicalItem1.textHeader.equals(textHeaderParam) &&
- myGraphicalItem1.textNormal.equals(textNormalParam)) {
- return myGraphicalItem1;
- } // if
- } // for
can be:
- for (GraphicalItem myGraphicalItem : graphicalItems) {
- if (myGraphicalItem.textHeader.equals(textHeaderParam) &&
- myGraphicalItem.textNormal.equals(textNormalParam)) {
- return myGraphicalItem;
- } // if
- } // for
Minor superficial remarks...
I haven't tried yet this sketch, but from the screen shot, it looks impressive.