Saturday 13 April 2019

java - Switching JPanel in JFrame from inside the JPanel

I'm trying to build a dynamic application based on buttons that switch the main Panel of a JFrame (which is the top content of my application) from inside the created panel.



The question is more related to a design question rather than a development question. I'm not sure of my design, but i'll try to explain it.



I have A JFrame representing my application which contains a JTabbedPane (and multiples Tabs in it). Each tab contains a default JPanel, and inside that JPanel, i'm calling a controller which is rendering my View (I'm trying to use a MVC Pattern).



But from the so called View, I have buttons which have to switch the content of the JPanel (Jpanel contained in the JTabbedPane). And I'm searching the best way to switch the View, without breaking the standard rules of OOP.



Schematically :




JFrame
JTabbedPane
JPanel
View1
Button (pointing somehow to View2)
JPanel
View3
Button (pointing somehow to View4)



When I click on the button from view 1, I would like to have this :



JFrame
JTabbedPane
JPanel
View2
...
JPanel
View3
Button (pointing somehow to View4)



And, once the View 2 is loaded, if I go to the View3 through the JTabbedPane and click the View3.button, I would like to have something like this :



JFrame
JTabbedPane
JPanel
View2
...
JPanel

View4
...


As I said it's more a design problem. Is my "design" good enough to not have to give to each component a reference of the JFrame ? How can I perform that ?



I hope there are not so much errors in my text, English is not my native language. Moreover, any corrections on my writing skills in english are welcome.



Thank you.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...