日期:2014-05-20 浏览次数:20711 次
public class WBBorderLayout { Frame f; GridBagLayout gbl=new GridBagLayout(); public WBBorderLayout(){ f=new Frame(); f.setLayout(gbl); int arr[][]={{0,0,3,0}, {1,0,0,0},{1,1,0,0},{1,2,0,0}, {2,0,3,0}}; Button b[]= new Button[5]; for(int i=0;i<arr.length;i++){ b[i]=new Button(" BUTTON "+i+" "); add(f, b[i], arr[i]); } f.pack(); f.setVisible(true); } public void add(Frame f,Button b,int arr[]){ GridBagConstraints gc=new GridBagConstraints(); gc.gridx=arr[0]; gc.gridy=arr[1]; gc.gridwidth=arr[2]; gc.gridheight=arr[3]; f.add(b, gc); } public static void main(String[] args) { WBBorderLayout mbl=new WBBorderLayout(); } }
gc.gridx=arr[0]; gc.gridy=arr[1];