Question

I need a good way to maintain multiple form level data for menue selection. So for example If I have A and B, each might Have 1 2 3 so A A1 A2 A3 B B1 B2 B3

And this can continue for long, so that I could have A -> A1 -> A1.1 -> A1.1.1 -.... I have the following class in place, works ok But I suspect we could have better.

I just need to perform selection ni a selection tree like Widget, but each level of selection comes in another form (in J2ME)

import java.util.Vector;
 public class Tag {
    private String tag;
    private Vector childTags;
    private Tag parent;

    Tag(String tag, Vector childtag)
    {
        this.tag = tag;
        this.childTags= childTags;
    }

    public void setChildTags(Vector childTags) {
        this.childTags = childTags;
    }

    public Vector getChildTags() {
        return this.childTags;
    }

    public String getTag() {
        return this.tag;
    }


    public String toString(int depth)
    {
                String a  ="";
        if(depth==0)
        {
            a = a + this.getTag();
        }

        if(this.getChildTags()!= null)
        {

                    for(int k=0;k <this.getChildTags().capacity(); k++)
                      {
                                for (int i=0; i<depth; i++ ) {
                                        a = a + ("-");
                                }
                                a = a+ ( ((Tag)this.getChildTags().elementAt(k)).toString(depth++));
        }   }
    return a;
        }


}

No correct solution

OTHER TIPS

You can use some classes to represent your menu commands. Think about 1 2 3 and A B C as commands and the combinations the way you compose them, so, applying some patterns here, you can use Command ( http://en.wikipedia.org/wiki/Command_pattern ) and Composite ( http://en.wikipedia.org/wiki/Composite_pattern ). Make them work together and it'll be much more straightforward to use and maintain it, instead of a mysterious and error prone "childTag vector".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow