2

因为我的程序有许多单独的类,所以我在我的项目中创建了 2 个文件夹(我使用的是 JDeveloper),名为“panels”和“buttons”,其中放置了扩展 JPanel 或 JButton 的相应类。我对我的所有类都使用了相同的包,以便放置在文件夹中的那些可以被其他未放置在同一文件夹中而不导入的类引用(我所有的类都属于同一个包,例如我的包裹)。

我的问题是我应该改变它并使目录的类属于一个单独的包(例如,“panels”目录中的类属于 mypackage.panels 包和“buttons”目录中的类属于 mypackage.buttons)?第一种方法效果很好,并且不需要导入,但我想知道这是否是“正确”的方法......

4

1 回答 1

2

Yes, in general I'd strongly encourage you to make your directory structure match your package structure. Some IDEs will enforce this, and other developers are likely to expect it - it's useful to know exactly where to find a particular file.

Now whether you really want separate packages for these controls is a different question, and one we can't answer.

于 2012-08-09T14:55:22.503 回答