问题描述
我的java swing应用程序中有大约3个帧。如何处理这些框架的正确方法是什么?我的意思是一些模式或其他东西。现在我总是有一个表示框架的类和一个用于面板的类,它是该框架中的主要部分。现在我将帧定义为静态变量,当我想隐藏它们时,我调用
classname.frameName.setVisible(false);
I have about 3 frames in my java swing application. What it the correct way how to handle with these frames? I mean some pattern or something else. Now I have always one class which represent frame and one class for panel which is main in this frame. Now I have defined frames as static variable and when I wanna hide them I call classname.frameName.setVisible(false);
这是正确的解决方案吗?
is this the correct solution?
推荐答案
除了<$ c $的(优秀)建议c> CardLayout 或 JFrame
包含多个 JDialog
个实例,以下是其他可能的策略单独或组合工作,将各种内容窗格折叠成一个框架。
Besides the (excellent) suggestions of a CardLayout
or JFrame
with multiple JDialog
instances, here are some other strategies which might work singly or in combination, to collapse a variety of content panes into a single frame.
-
JDesktopPane
/JInternalFames
()。 -
JSplitPane
()。 -
JTabbedPane
()。 -
JLayeredPane
,如果你有勇气()。 -
JToolBar
- 如果需要可浮动()。 - 。
JDesktopPane
/JInternalFames
(Tut.).JSplitPane
(Tut.).JTabbedPane
(Tut.).JLayeredPane
, if you're feeling brave (Tut.).JToolBar
- floatable if needed (Tut.).- Different constraints of a
JPanel
in a nested layout.
可能还有更多..
当然,正如亚当斯基指出的,还有一些进一步的怪癖要考虑..
Of course, as Adamski pointed out, there are some further quirks to consider..
可能将它们组合为子菜单。
Possibly combine them as sub-menus.
这篇关于使用2个或更多帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!