继续java图形化页面的学习,今天学的是页面的分区和布局
import java.awt.*;
public class _1016 {
public static void main(String[] args) {
Frame frame = new Frame();
frame.setBounds(500, 500, 300, 300);
frame.setAlwaysOnTop(true);
//边界布局
// BorderLayout borderLayout = new BorderLayout();
// frame.setLayout(borderLayout);
// borderLayout.setVgap(10);//设置纵向间距
// borderLayout.setHgap(10);//设置横向间距
//流式布局
// FlowLayout flowLayout = new FlowLayout();
// flowLayout.setAlignment(FlowLayout.LEFT);//对齐
// frame.setLayout(flowLayout);
// frame.setVisible(true);
// frame.add(new Button("1.button"), BorderLayout.EAST);
// frame.add(new Button("2.button"), BorderLayout.WEST);
// frame.add(new Button("3.button"), BorderLayout.SOUTH);
// frame.add(new Button("4.button"), BorderLayout.NORTH);
// frame.add(new Button("5.button"), BorderLayout.CENTER);
//卡片布局
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(2);
frame.setLayout(gridLayout);
// gridLayout.setRows(10);
// for(int i=0;i<10;i++)
// {
// frame.add(new Button(i+".button"));
//
//
//
// }
Panel topPanel = new Panel();
topPanel.setBackground(Color.ORANGE);
topPanel.setLayout(gridLayout);
for(int i=0;i<5;i++)
topPanel.add(new Button(i+".button"));
frame.add(topPanel);
Panel bottomPanel = new Panel();
bottomPanel.setBackground(Color.PINK);
bottomPanel.setLayout(new FlowLayout());
for(int i=0;i<5;i++)
bottomPanel.add(new Button(i+".button"));
frame.add(bottomPanel);
frame.setVisible(true);
}
}
标签:BorderLayout,java,frame,学习,add,new,button,Button,10.16 From: https://www.cnblogs.com/zangbotao/p/18471104