GUI中各种布局

1  BorderLayout

package GUI;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.TextField;

public class BorderLayoutTest 
{
 public static void main(String[] args) 
 {
	//定义Frame,BorderLayout布局管理器,并指定布局为BorderLayout
	 Frame f=new Frame("This is a FloWlayout Test");
	 BorderLayout borderlayout=new BorderLayout();
	 f.setLayout(borderlayout);
	 
	 //创建文本域,并设置文本域中初始字符的大小
	 TextField one =new TextField("one",10);
	 TextField two =new TextField("two",10);
	 TextField three =new TextField("three",10);
	 
	 //添加文本域到指定位置
	 f.add("South",one);
	 f.add("North",two);
	 f.add("Center",three);
	 
	 //设置Frame的大小并显示
	 f.setSize(200,100);
	 f.show();
	 
	 
 }

}

2CardLayout

package GUI;

import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Frame;

import javax.swing.JFrame;

public class CardLayoutTest 
{
  public static void main(String[] args) 
  {
	//定义Frame  CardLayout布局管理器,并指定布局为CardLayout
	  Frame f=new Frame("This is a CardLayoutTest!");
	  CardLayout cardlayout = new CardLayout();
	  f.setLayout(cardlayout);
	  
	  //定义按钮
	  Button one = new Button("one");
	  Button two = new Button("two");
	  Button three = new Button("three");
	  Button four = new Button("four");
	  Button five = new Button("five");
	  
	  //t添加按钮
	  f.add(one,"one");
	  f.add(two,"two");
	  f.add(three,"three");
	  f.add(four,"four");
	  f.add(five,"five");
	  
	  //设置frame大小并显示
	  f.setSize(200,100);
	  f.show();
	  
	  
  }
}

3  FlowLayout
package GUI;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;

public class FlowLayoutTest 
{
  public static void main(String[] args) 
  {
	//定义Frame。Flowlayout布局管理器,并指定布局为FlowLayout
	  Frame f=new Frame("this is a FlowLayout Test");
	  FlowLayout flowlayout = new FlowLayout(FlowLayout.LEFT,30,30);
	  f.setLayout(flowlayout);
	  
	  //创建按钮
	  Button one = new Button("one");
	  Button two= new Button("two");
	  
	  //添加按钮到指定位置
	  f.add(one);
	  f.add(two);
	  
	  //设置Frame的大小并显示
	  f.setSize(200,100);
	  f.show();
  }
}
4GridLayout

package GUI;


import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;


public class GridLayoutTest
{


public static void main(String[] args) 
{
//定义Frame,GridLayout布局管理器,并指定布局为GridLayout
Frame f=new Frame("This is a GridLayout Test!");
GridLayout gridlayout=new GridLayout(3,3);
f.setLayout(gridlayout);

//创建按钮
Button one =new Button("one");
Button two =new Button("two");
Button three =new Button("three");
Button four =new Button("four");
Button five =new Button("five");

//添加按钮到指定位置
f.add(one);
f.add(two);
f.add(three);
f.add(four);
f.add(five);

//设置Frame 的大小并显示
f.setSize(200,100);
f.show();





}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值