Search code examples
javafieldpanelframeconcept

Should the panels be fields inside the frame?


I created a frame with almost 20 panels inside (all with different kind and characteristics) simply creating them and adding them to the content Panel and remembering his order number for accessing them.

But now I'm trying to generate an UML diagram from the source code and I noticed that i don't have any reference to this panels inside the frame. Should I create 20 field panels and reference them one by one? Or It's just fine? I don't know the right way, thanks!

P.S: I don't know if this matters but my language is Java


Solution

  • The way you write about your panels (all with different kind and characteristics) I suspect that these panels also have different classes.

    So to access a specific panel your code probably looks like

    ((MyPanelType1) getContentPane().getComponent(0)).someMethod();
    

    whereas with fields for every panel

    private MyPanelType1 firstPanel;
    

    the code would look like

    firstPanel.someMethod();
    

    Now decide which code is easier to read, and decide accordingly.