//JButton1.java
//布局管理器
//2009-10-26 《程序设计百事通》
//<applet code=JButton1 width=400 height=500>
//</applet>
import javax.swing.*;
import java.awt.*;
public class JButton1 extends JApplet
{
JButton testButton1=new JButton("button1");
JButton testButton2=new JButton("button2");
JButton testButton3=new JButton("button3");
JButton testButton4=new JButton("button4");
JButton testButton5=new JButton("button5");
JPanel xP=new JPanel();//JPanel 即是构件,也是一个小的layout
JPanel yP=new JPanel();
public void init(){
Container cp=getContentPane();
cp.setLayout(new FlowLayout());//将JPanel对象由FlowLayout管理
cp.add(xP);
cp.add(yP);
BoxLayout bl=new BoxLayout(xP,BoxLayout.X_AXIS);//将Button1、Button2、Button3放入xP,X_AXIS X轴
xP.setLayout(bl);
xP.add(testButton1);
xP.add(testButton2);
xP.add(testButton3);
yP.setLayout(new BoxLayout(yP,BoxLayout.Y_AXIS));//将Button4、Button5放入yP。
yP.add(testButton4);
yP.add(testButton5);
}
}