e571. creating a container.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 27 行
TXT
27 行
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);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?