[英]What is the purpose of Panels in java
我是一名正在服用java的高中生我通常没有很多问题,但我没有一点研究就弄清楚但是我的老师坚持要求所有学生在构建GUI时都使用面板。我没有问题但是我没有问题无法得到一个体面的答案,澄清将组件放入Panel中的目的
By using Panel
s it's easier to group components and arrange them in a Frame
. 通过使用
Panel
可以更轻松地对组件进行分组并将其排列在Frame
。 Every Panel
can have it's own layout. 每个
Panel
都可以拥有自己的布局。 So you could give your outer Frame a BorderLayout
and put a Panel
into the center. 因此,您可以为外部框架提供
BorderLayout
并将Panel
放入中心。 The Panel
then can have let's say a GridBagLayout
for it's components. 然后,
Panel
可以为它的组件说一个GridBagLayout
。
The more complex the UIs are which you are building the more grateful you are for this possibility. 您正在构建的UI越复杂,您就越感激这种可能性。
Panels exist for a few reasons. 小组存在的原因有几个。
One is to make organization easier (both from a code and a UI standpoint) in windows with clear multiple areas. 一种是在具有明确多个区域的窗口中使组织更容易(从代码和UI角度来看)。 Having more than one panel in a single frame would let you separate vastly different code into different classes.
在一个框架中有多个面板可以让您将截然不同的代码分成不同的类。
Another reason is for frames that totally change appearance on an action. 另一个原因是框架完全改变了动作的外观。 Many beginners are inclined to keep one panel in the frame for situations like this and simply wipe the panel and put new components in on each change.
许多初学者倾向于在这种情况下将一个面板保留在框架中,只需擦拭面板并在每次更改时放入新组件。 However, a much simpler (and more efficient) panel-driven solution is to have one panel for each different version of the frame and swap them out.
然而,更简单(也更有效)的面板驱动解决方案是为每个不同版本的框架提供一个面板并将其交换出来。
Lastly, it lets you use different types of layouts in different areas of the frame, which leads to more dynamic and flexible UIs. 最后,它允许您在框架的不同区域使用不同类型的布局,从而实现更加动态和灵活的UI。
A panel is a container. 面板是一个容器。
There are many other reasons for using panels, these are just a few that pop to mind 使用面板还有很多其他原因,这些只是我想到的一些原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.