Hey all,
I've still not decided whether to extend JFrame or have it as a private member variable (of my MainWindow class... which I may rename, but that's by the by)
Most examples on the web and theads ont here and other formum that I've seen seem to say extending JFrame is the best way.
Arguments for extending JFrame:
Other classes will be able to use all the public methods of JFrame, thus making your class more flexible. The class does seem to pass the "IS-A" test for a JFrame. It represents a frame on the screen. Arguments for private encapsulation:
Other classes will NOT be able to access the public methods of JFrame, so you do not have to think about what will happen if other classes use them. In either case, I will probably have member variables for the various JButtons and JMenuItems, since I will have "hook" methods to register listeners for them. It seems a bit messy to have them both as member variables, and using .add() to add them to the frame. As far as I see it, OOP principles mean that JFrame should be extended when adding some sort of extra JFrame type behaviour. I'm not sure this is the case here. The JFrame is simply being used to display (via add()) the components on the screen. Is this an argument for the "HAS-A" relationship? Does anyone have any comments on my arguments, or even any more arguments for either side? I've searched, but am unable to find much. Links to FAQs or other threads where I may get help gratefully accepted.
Michal