简体   繁体   English

向Java应用程序添加组件的最佳方法是什么

[英]What is the best way to add components to a java application

Right now I create all of my swing components in the same class that has my method "main", this class keeps growing and looking more unorganized with each component created. 现在,我在具有我的方法“ main”的同一个类中创建所有的swing组件,该类不断增长,并且每个创建的组件看起来更加杂乱无章。 Should I create another class to create the components and pass a the frame by reference? 我应该创建另一个类来创建组件并通过引用传递框架吗? Or should I let my current class keep growing? 还是应该让我目前的课程保持增长? Is there a best practice or industry standard? 是否有最佳做法或行业标准?

Thank you for any input. 感谢您的投入。

The short answer is "it depends." 简短的答案是“取决于情况”。 If it is a simple UI, you can get away with one class. 如果它是一个简单的UI,那么您可以不用上一堂课。 But if there are several independent windows or other components, consider creating separate classes. 但是,如果有几个独立的窗口或其他组件,请考虑创建单独的类。 Then instantiate them in your main class. 然后在您的主类中实例化它们。

For example, consider a banking application. 例如,考虑一个银行应用程序。 There may be different windows for the different functions (withdraw, deposit, transfer, balance inquiry). 不同功能(取款,入金,转账,余额查询)的窗口可能不同。 You could have four different classes that extend JPanel. 您可以有四个不同的类来扩展JPanel。 Then in your main class, you can instantiate these classes and assemble them. 然后,在您的主类中,您可以实例化这些类并进行组装。

Just a thought. 只是一个想法。

暂无
暂无

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

相关问题 在Eclipse中分析Java应用程序的最佳方法是什么? - What is the best way to profile a Java application in Eclipse? 在Java应用程序中管理时间的最佳方法是什么? - What is the best way to manage Time in a Java application? 在MVC架构中公开Java组件(如JButton)的最佳方法是什么? - What's the best way to expose Java components such as a JButton in an MVC architecture? 为Java Swing应用程序添加自更新功能的最佳方法是什么? - What's the best way to add a self-update feature to a Java Swing application? 将Java桌面应用程序部署到多个平台的最佳方法是什么? - What is the best way to deploy a Java desktop application to multiple platforms? 移植 Java 桌面应用程序以在浏览器中运行的最佳方法是什么? - What is the best way to port a java desktop application to run in browser? 在运行 RabbitMQ 消费者的情况下安全结束 java 应用程序的最佳方法是什么 - What is the best way to safely end a java application with running RabbitMQ consumers 在Java中使用XML配置文件到我的应用程序的最佳方法是什么? - What is the best way to work with xml configurations file to my application in java? 在java应用程序中保存用户设置的最佳方法是什么? - What is the best way to save user settings in java application? 在 Java 应用程序中使用经过训练的 LibSVM 模型的最佳方法是什么? - What is the best way to use a trained LibSVM model inside a Java application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM