简体   繁体   中英

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. 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. 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. Then in your main class, you can instantiate these classes and assemble them.

Just a thought.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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