/** |
* 功能:BorderLayout的简单案例 |
* 1.继承JFrame |
* 2.定义你需要的组件 |
* 3.创建组件(构造函数) |
* 4.添加组件 |
* 5.对窗体设置 |
* 6.显示窗体 |
*/ |
package com.jiemian; |
import java.awt.*; |
import javax.swing.*; |
public class Text1 extends JFrame{ |
JButton jb1,jb2,jb3,jb4,jb5; |
public static void main(String[] args) { |
// TODO Auto-generated method stub |
Text1 text1= new Text1(); |
} |
|
public Text1(){ |
|
//设置组件 |
jb1= new JButton( "北部" ); |
jb2= new JButton( "南部" ); |
jb3= new JButton( "中部" ); |
jb4= new JButton( "西部" ); |
jb5= new JButton( "东部" ); |
|
//添加组件 |
this .add(jb1, BorderLayout.NORTH); |
this .add(jb2, BorderLayout.SOUTH); |
this .add(jb3, BorderLayout.CENTER); |
this .add(jb4, BorderLayout.WEST); |
this .add(jb5, BorderLayout.EAST); |
|
//对窗体设置 |
this .setTitle( "边界布局案例" ); |
this .setSize( 300 , 200 ); |
this .setLocation( 200 , 100 ); |
this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
this .setVisible( true ); |
} |
} |