简体   繁体   English

Java Swing-做基于阶段的GUI的正确方法是什么?

[英]Java Swing - What's the proper way of doing a stage based GUI?

I'm currently developing the menu of my application and I would like to know what's the proper way of coding a "stage based menu". 我目前正在开发应用程序的菜单,我想知道编码“基于阶段的菜单”的正确方法是什么。 What I mean by stage based menu is that, user clicks a button, the entire interface changes to the next "stage". 我所说的基于阶段的菜单的意思是,用户单击一个按钮,整个界面将变为下一个“阶段”。 Here are the pictures I designed in Photoshop in order to explain my idea: 这是我在Photoshop中设计的图片,目的是解释我的想法: 主菜单

管理菜单

First picture would be the first stage and the second picture the second. 第一张图片是第一阶段,第二张图片是第二阶段。 Each round looking thing is a JButton 每一轮看起来都是一个JButton

So far I got the main menu (fist picture) made on eclipse using WindowBuilder, made it as a JPanel and then I instantiate it on the window class. 到目前为止,我已经使用WindowBuilder在eclipse上制作了主菜单(第一张图片),使其成为JPanel,然后在window类上实例化了它。

My idea was to have an event listener listen for clicks on each button and then once the even is triggered, have the JPanel variable on the frame change to the next "stage". 我的想法是让事件侦听器侦听每个按钮的单击,然后触发偶数后,将框架上的JPanel变量更改为下一个“阶段”。 So I was wondering if this is actually the proper way of doing this or are there any better ways? 所以我想知道这是否是这样做的正确方法,还是有更好的方法?

You could use a Card Layout to make it easy to swap panels. 您可以使用“ Card Layout来轻松交换面板。

Check out the section from the Swing tutorial on How to Use Card Layout for more information and examples. 请参阅Swing教程中有关如何使用卡布局的部分, 获取更多信息和示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM