0

I created a FrameClass so every panel in my program has one frame to use. My teacher hates multiple frames.

FrameClass frame = new FrameClass();

My problem is that when I implement the code above in every JPanel classes frames pops out whenever I do action to go to the next panel. I knew that new FrameClass() triggers the action. Is there a way similar to this that can be done to inherit FrameClass attributes.

  • I think rather than "newing" your Frame subclass in every Panel subclass, you need a FrameManager class that "has a" Frame member and "has a" bunch of Panel members and manages how they relate to each other, like which panel is visible in the frame... – geneSummons Dec 16 '16 at 19:11
  • @geneSummons there are buttons in each panel classes that redirects to another panel class. By clicking the button the previous panel will not be visible and the next panel will be visible. –  Dec 16 '16 at 19:20
  • 1
    1) *"My teacher hates multiple frames."* The teacher is very sensible. See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) Also, don't extend either `JFrame` ***or*** `JPanel` unless you can explain why it is necessary. Prefer [composition over inheritance](https://en.wikipedia.org/wiki/Composition_over_inheritance). – Andrew Thompson Dec 16 '16 at 22:41
  • 1
    It's been over 3 hours since you've posted this question, and while you've gotten comments, you've received no unifying decent answer. If you're still in search of a decent answer, please consider improving your question by -- 1) creating and posting a valid [SSCCE](http://SSCCE.org) , 2) explaining your code structure in a little more detail. – Hovercraft Full Of Eels Dec 16 '16 at 22:48

0 Answers0