比较复杂一点的布局啊,呵呵,都是些简单的小组合,对我来说很复杂了。这次加上了个关闭窗口的语句。csdn上找的,很好用,源代码添上就可以用。
import java.awt.*;
import java.awt.event.*;
public class TenButtons{
public static void main(String args[]){
Frame f = new Frame("TenButtons~");
f.setLayout(new GridLayout(2,1));
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
Panel p4 = new Panel();
//p1.setLayout(new FlowLayout());
Button p11 = new Button("Button");
Button p12 = new Button("Button");
p2.setLayout(new BorderLayout());
p2.add(new Button("Button"),BorderLayout.WEST);
p2.add(new Button("Button"),BorderLayout.EAST);
p3.setLayout(new GridLayout(2,1));
p3.add(new Button("Button"));
p3.add(new Button("Button"));
p1.setLayout(new BorderLayout());
p1.add(p11,BorderLayout.WEST);
p1.add(p12,BorderLayout.EAST);
p1.add(p3,BorderLayout.CENTER);
p4.setLayout(new GridLayout(2,2));
p4.add(new Button("Button"));
p4.add(new Button("Button"));
p4.add(new Button("Button"));
p4.add(new Button("Button"));
p2.add(p4,BorderLayout.CENTER);
f.add(p1);
f.add(p2);
f.pack();
f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.out.println("program exited");
System.exit(0);
}
});
}
}
Tags -
awt ,
布局管理器
文章来源:
http://www.tt-shopping.com/kevinlau/read.php/91.htm