java swing CardLayout 中每个卡的单独类
出于架构和设计的目的,我想设计我的 GUI,并为 Java Swing CardLayout 中的每张卡设计一个类。然后有一个构建 GUI 的 mainapp。我现在很难做到这一点。
我想为主菜单提供一个类,其中包含所有按钮位置等,然后实例化该卡并将其添加到另一个类的布局中。有谁知道如何实现这一目标?
For architecture and design purposes I would like to design my GUI with a class for each card in a Java Swing CardLayout. and then have a mainapp that builds the GUI. I am having trouble doing this right now.
I would like to example have a class for the main menu with all the button locations etc. and then just instantiate that card and add it to the layout in another class. Does anyone know how to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您想为使用 CardLayout 的类提供一个公共 loadCard 方法,例如,
cardHolderPanel 是保存卡片的容器。
由于您创建的类充当卡片,请考虑让它们全部从抽象基类或接口扩展,该接口具有允许此类保存其自己的键 String 的方法。或者直接使用 JComponent name 属性让组件保存自己的键 String,可以通过 getName() 轻松获取该键 String。
要获得更详细的答案,您可能需要向我们提供有关您当前应用程序及其结构的更多详细信息。
Perhaps you want to give your class that uses the CardLayout a public loadCard method, something like
where cardHolderPanel is the container that holds the cards.
Since your creating classes to act as cards, consider having them all extend from a base abstract class or an interface that has a method that allows this class to hold its own key String. Either that or simply use the JComponent name property to have a component hold its own key String, one that can easily be obtained via
getName()
.For a more detailed answer, you may need to give us more details on your current application and its structure.
非常简单的示例,包含从不同 Java 类生成的 Swing 对象
very simple example that held Swing Objects generated from different Java Classes