我是一名正在服用java的高中生我通常没有很多问题,但我没有一点研究就弄清楚但是我的老师坚持要求所有学生在构建GUI时都使用面板。我没有问题但是我没有问题无法得到一个体面的答案,澄清将组件放入Panel中的目的
By using Panel
s it's easier to group components and arrange them in a Frame
. Every Panel
can have it's own layout. So you could give your outer Frame a BorderLayout
and put a Panel
into the center. The Panel
then can have let's say a GridBagLayout
for it's components.
The more complex the UIs are which you are building the more grateful you are for this possibility.
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. 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.
A panel is a container.
There are many other reasons for using panels, these are just a few that pop to mind
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.