java学习之布局管理器

——————————————————————————————————————————————————————————————

一。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就业教程》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值