A while ago, I read that the best way to switch between different "screens" in an application would be to set up different JFrame
s and then simply dipose the first and call the second. For example I have Screen A extending JFrame
and Screen B extending JFrame
, on a button that should switch to the next screen I would write something like that
JButton button = new JButton("show next screen");
button.addActionListener(){
new ScreenB();
frameA.dispose(); // assumed that we coded something like frameA = this earlier
}
Now the problem is that between the changeover of the two frames, I see for let's say 1/10 either Screen A or Screen B, which is very ugly. What would be a better solution? Extending the screens as Container
and set them as ContentPane
for the always the same JFrame
?