一个很好的 Swing 项目,用于学习最佳实践

发布于 2024-12-13 06:10:48 字数 1491 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伪装你 2024-12-20 06:10:48

我学习 Swing 最佳实践的方式是阅读 JDK 中的 Swing 源代码并进行实践。遵循Sun 的做法,您就会走上正确的道路。

阅读 JTable、JTree、JScrollPane、各种 LookAndFeels、SwingWorker、SwingUtilities 的实现。它们的事件处理和 MVC 模式极其复杂,但非常具有可读性、可维护性和可扩展性。本质上,每次使用组件时,都要阅读源代码并了解它们的用途和原因。最终,你会开始做同样的事情。

最重要的是,代码。编写一些大型程序,您将开始看到一些看起来不正确或不理想的情况。来 Stack 看看你做错了什么或者可以做得更好。写点别的东西,然后做同样的事情。

也就是说,以下项目有(或可能有)好的代码:

SwingX - SwingX 的维护者是 Sun/ex-Sun 人员,我一直认为它是未来 Swing 功能的非官方孵化器。

Squirrel(一个 JDBC 客户端) - 我实际上并没有查看它们的源代码,但我已经使用这个程序很多年了,它没有表现出编写糟糕的 Swing 程序中的任何常见缺陷。考虑到它的功能有多强大,以及它的工作效果有多好,我认为它写得非常好。

InfoNode(一个强大的对接框架) - 我已经浏览了他们的相当多的代码,而且它非常可靠。

JFreeChart(一个强大的图表库) - 不是最好的代码,但比平均水平要好得多,特别是考虑到它这是一个旧项目,从来没有真正打算做人们使用它做的所有事情。也就是说,它具有很强的可扩展性,而且我在根据我的需求(这比它的初衷要多得多)塑造它时从来没有遇到过问题。

GlazedLists(一个高性能的基于事件的列表库) - 不完全是 Swing,但它的事件处理与 Swing 类似。他们还实现了 Swing 模型和一些速度极快的自定义组件。

JIDE 公共层:大量自定义组件的集合,作为其商业组件的基础。我还没有浏览过他们的代码,但是他们的组件很漂亮,而且由于他们的主要关注点是商业 Swing 组件,所以我再次强调他们的代码是可靠的。

The way I learned Swing best practices was reading the Swing source code in the JDK and practice. Follow Sun's practices and you'll be on the right path.

Read the implementations of JTable, JTree, JScrollPane, the various LookAndFeels, SwingWorker, SwingUtilities. Their event handling and MVC patterns are extremely complex but very readable, maintainable, and extensible. Essentailly, every time you use a component, go read the source code and understand what and why they do it. Eventually, you'll start doing the same thing.

And most importantly, code. Write some large programs, and you'll start seeing things that don't seem right or optimal. Come on to Stack and find out what you're doing wrong or could do better. Write something else, and do the same.

That said, the following projects have (or probably have) good code:

SwingX - The maintainers of SwingX were Sun/ex-Sun people, and I've always thought of it as unofficial incubator for future Swing features.

Squirrel (A JDBC client) - I haven't actually looked at their source, but I've used the program for years and it doesn't show any of the common flaws in badly written Swing programs. With how powerful it is, and how well it works, I would put money that's its extremely well written.

InfoNode (A powerful docking framework) - I've gone through quite a bit of their code, and its pretty solid.

JFreeChart (A powerful charting library) - Not the greatest code, but much better than average, especially taking into account its an old project that was never really intended to do everything people are using it for. That said, it is very extensible, and I've never had a problem molding it to my needs (which are much, much more than its original intentions).

GlazedLists (A highly performant event-based list library) - Not exactly Swing, but it's event handling is similar to Swing. They also have implementations of Swing models and some custom components that are extremely fast.

JIDE Common Layer: A massive collection of custom components that serves as the basis for their commercial components. I haven't gone through their code, but their components are beautiful, and since their primary focus is commercial Swing components, once again, I'd put money that their code is solid.

小女人ら 2024-12-20 06:10:48

我发现看到用 Swing 编写的专业品质应用程序非常有趣,例如 IntelliJ IDEA社区版。现在它是开源的,您可以查看代码并开始深入研究。不过请注意,没有注释!

I found it very interesting to see a professional-quality application written in Swing, such as IntelliJ IDEA Community Edition. Now that it's open-sourced, you can check out the code and start digging in. Be forewarned though, there are no comments!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文