您的位置:首页 > 编程语言 > Java开发

java学习之布局管理器

2016-07-20 17:41 507 查看


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

一。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就业教程》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: