——————————————————————————————————————————————————————————————
一。BorderLayout类
推荐:http://blog.csdn.net/liujun13579/article/details/7772215
二。flowLayout.类
推荐:http://blog.csdn.net/liujun13579/article/details/7771191
——————————————————————————————————————————————————————————————————————
三。GridLayout类
推荐:http://blog.csdn.net/liujun13579/article/details/7772491
————————————————————————————————————————————————————————
四。CardLayout
推荐:http://blog.csdn.net/liujun13579/article/details/7773945
——————————————————————————————————————————————————————————————————
五。取消布局管理器
——————————————————————————————————————————————————————————————————
(1)testLayout.java
package testLayout;
import java.awt.*;
import java.awt.event.*;
public class testLayout extends Frame {
Panel pL=new Panel();
CardLayout cl=new CardLayout();
Panel pR=new Panel();
public testLayout()
{
add(pL,"West");
add(pR);
pL.setLayout(new GridLayout(3,1));
Button btnOne=new Button("前");
Button btnTwo=new Button("后");
Button btnThree=new Button("显示");
pL.add(btnOne);
pL.add(btnTwo);
pL.add(btnThree);
//right
pR.setLayout(cl);
Button btnFirst=new Button("First");
Button btnSecond=new Button("Second");
Button btnThird=new Button("Third");
//添加卡片组件,需要一个关键字
//public void addLayoutComponent(Component comp, Object constraints)
pR.add(btnFirst,"1");
pR.add(btnSecond,"2");
pR.add(btnThird, "3");
//增加监听器
MyActionListener ma=new MyActionListener();
btnOne.addActionListener(ma);
btnTwo.addActionListener(ma);
btnThree.addActionListener(ma);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
}
public class MyActionListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(e.getActionCommand().equals("前"))
{
cl.previous(pR);
}else if(e.getActionCommand().equals("后"))
{
cl.next(pR);
}else
{
cl.show(pR, "3");
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
testLayout dw=new testLayout();
dw.setSize(400, 400);
dw.setTitle("test");
dw.setVisible(true);
}
}
——————————————————————————————————————————————————————————————————
自《张孝祥--java就业教程》