面板组件

一、代码如下

package www.tainiu.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ac__MianBanZuJian__V1 extends JFrame {
	JPanel jp1,jp2;
	JButton jb1,jb2,jb3,jb4,jb5,jb6;
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ac__MianBanZuJian__V1 mv= new ac__MianBanZuJian__V1();
	}
	
	public ac__MianBanZuJian__V1() {
		// TODO Auto-generated constructor stub
		//定义组件
		this.jp1= new JPanel();
		this.jp2= new JPanel();
		
		this.jb1= new JButton("西瓜");
		this.jb2= new JButton("苹果");
		this.jb3= new JButton("桃子");
		this.jb4= new JButton("梨子");
		this.jb5= new JButton("桔子");
		this.jb6= new JButton("柿子");
		
		//设置布局方式
		//this.setLayout(new GridLayout(3, 1));
		
		//添加组件
		this.jp1.add(jb1);
		this.jp1.add(jb2);
		
		this.jp2.add(jb4);
		this.jp2.add(jb5);
		this.jp2.add(jb6);
		
		this.add(jp1, BorderLayout.NORTH);
		this.add(jb3, BorderLayout.CENTER);
		this.add(jp2, BorderLayout.SOUTH);
		
		
		//设置容器及属性
		this.setSize(300, 300);
		this.setLocation(200, 200);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setVisible(true);
	}

}

 

posted @ 2017-09-19 19:44  18513757531  阅读(121)  评论(0编辑  收藏  举报