[英]show one panel after button is clicked and other panel when second button is clicked in the same frame
I am creating a Swing based application , which actually consist of two buttons as shown below - 我正在创建一个基于Swing的应用程序,它实际上包含两个按钮,如下所示 -
now what i want is when first button is clicked it must perform a action like showing a panel containing label, textfields , and some buttons in the same frame as shown below - 现在我想要的是当点击第一个按钮时它必须执行一个动作,如显示包含标签,文本字段和一些按钮的面板,如下所示 -
and when second button is clicked it will show another panel in the same frame as shown below .. 当点击第二个按钮时,它将在同一帧中显示另一个面板,如下所示。
the thing is i am not understanding how to make this interface in action by providing event handler and action listener .. So please letme me know how can i archive this . 事情是我不知道如何通过提供事件处理程序和动作监听器来使这个界面在行动。所以请让我知道如何存档这个。 Any help would be appreciated .. Thanks
任何帮助将不胜感激..谢谢
There are 2 approaches. 有两种方法。
CardLayout
based. 基于
CardLayout
。
Create all the panels (empty, panel with fields, panel with list) and add them in a container with CardLayout
(the empty one is default). 创建所有面板(空白,带有字段的面板,带有列表的面板)并将它们添加到具有
CardLayout
的容器中(默认为空)。 On click buttons swap visible cards (panels) showing necessary one. 在单击按钮上交换显示必要的卡片(面板)。
Recreation based. 以娱乐为主。
On click button create a new panel with new content. 在单击按钮上创建包含新内容的新面板。 Remove the old one from container and add the newly created pane.
从容器中删除旧的并添加新创建的窗格。 After then call:
之后致电:
container.revalidate(); container.repaint();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.