How to use setVisible in JFrames?

房东的猫 提交于 2019-12-01 00:38:34
mKorbel

Consider using CardLayout instead of hunting for how many JFrames there are. Then..

  • only one JFrame would be needed
  • any of Next/Back Actions will be only switching between cards

There are lots of examples in this forum - e.g. as shown here.

That is an odd & quirky GUI. I suggest instead to run a JFrame for the main GUI, and when the user wants to search, pop a JOptionPane (or modal JDialog) to accept the details to search for. This will not have the effect described above, but will follow the 'path of least surprise' for the end user.

If you want to destroy a JFrame releasing all associated resources you shold call dispose() method on it.

You may place your JFrames on a list data structure and keep a reference to current position according to the window you are displaying. In that way it will be easy to move to next and previous. But note that each frame added to the list will use memory and will have its state as you placed it in to the list.

If you are trying to create a wizard like UI, you should look up Sun(oracle)tutorial here.

create the instance of your main window in next() window.. and use same method which you chosed befoe to hide your main window, for example if your main window is named as gui then what we have to do is.

gui obj = new gui();

and if you click on back button now than do these also

this.setVisibility(false);
obj.setVisibility(true);

that's all you need.

good luck.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!