A container holds one or more child components. A container has a layout that determines how the child components are arranged within the container. This example creates a frame with a text area in the center and a row of buttons at the bottom. The buttons are placed in a container.
// Create a container with a flow layout, which arranges its children horizontally
Panel panel = new Panel();
// A container can also be created with a specific layout
panel = new Panel(new FlowLayout(FlowLayout.RIGHT));
// Add several buttons to the container
panel.add(new Button("A"));
panel.add(new Button("B"));
panel.add(new Button("C"));
// Create frame with a text area in the center
Frame frame = new Frame();
Component comp = new TextArea();
frame.add(comp, BorderLayout.CENTER);
// Add the container to the bottom of the frame
frame.add(panel, BorderLayout.SOUTH);
// Show the frame
int width = 300;
int height = 300;
frame.setSize(width, height);
frame.setVisible(true);
|
e571. Creating a Container
最新推荐文章于 2025-06-12 14:50:50 发布
3327

被折叠的 条评论
为什么被折叠?



