关于BorderLayout

来源:百度知道 编辑:UC知道 时间:2024/06/23 23:11:04
如何把以下程序改成BorderLayout布局管理器,然后再向每个区域加入一个按钮?
import java.awt.*;
public class MyFrame2{
public static void main(String args[]){
Panel p=new Panel();
Frame f=new Frame("hello");
f.setSize(700,700);
f.setVisible(true);
p.setLayout(new FlowLayout(FlowLayout.LEFT,50,50));
p.setSize(300,300);
f.setBackground(Color.green);
p.add(new Button("eqwe1"));
p.add(new Button("eqwe2"));
p.add(new Button("eqwe3"));
p.setBackground(Color.blue);
f.add(p);
p.setVisible(true);
}
}

import java.awt.*;
public class MyFrame2{
public static void main(String args[]){
Panel p=new Panel();
Frame f=new Frame("hello");
f.setSize(700,700);
f.setVisible(true);
p.setLayout(new BorderLayout());
p.setSize(300,300);
f.setBackground(Color.green);
p.add(new Button("eqwe1"),"North");
p.add(new Button("eqwe2"),"Center");
p.add(new Button("eqwe3"),"West");
p.add(new Button("eqwe4"),"South");
p.add(new Button("eqwe5"),"East");
p.setBackground(Color.blue);
f.add(p);
p.setVisible(true);
}
}