其他分享
首页 > 其他分享> > 三种布局管理器

三种布局管理器

作者:互联网

流式布局

public class demo02 {
    public static void main(String[] args) {
        Frame frame=new Frame();
        Button button1=new Button("a");
        Button button2=new Button("b");
        Button button3=new Button("c");

        frame.setLayout(new FlowLayout(FlowLayout.CENTER));
        frame.setResizable(false);
        frame.setBackground(Color.red);
        frame.setSize(400,400);
        frame.add(button1);frame.add(button2);frame.add(button3);
        frame.setVisible(true);
    }
}

 

东西南北中

public class demo03 {
    public static void main(String[] args) {
        Frame frame=new Frame();
        Button east=new Button("east");
        Button west=new Button("west");
        Button north=new Button("north");
        Button  south=new Button("south");
        Button center=new Button("center");


        frame.setResizable(false);
        frame.setBackground(Color.red);
        frame.setSize(400,400);
        frame.setVisible(true);
        frame.add(east,BorderLayout.EAST);
        frame.add(west,BorderLayout.WEST);
        frame.add(south,BorderLayout.SOUTH);
        frame.add(north,BorderLayout.NORTH);
        frame.add(center,BorderLayout.CENTER);

    }
}

 

 

 

 

 

表格布局

public class demo04 {
    public static void main(String[] args) {
        Frame frame=new Frame();
        Button east=new Button("east");
        Button west=new Button("west");
        Button north=new Button("north");
        Button  south=new Button("south");
        Button center=new Button("center");


        frame.setResizable(false);
        frame.setBackground(Color.red);
        frame.setSize(400,400);
        frame.setVisible(true);
        frame.setLayout(new GridLayout(3,4));
        frame.add(east);
        frame.add(west);
        frame.add(north);
        frame.add(south);
        frame.add(center);
    }
}

 

 

 

标签:管理器,west,frame,布局,add,三种,north,new,Button
来源: https://www.cnblogs.com/guojianglong/p/16537590.html