//网格布局管理器
import java.awt.*;
import javax.swing.*;
public class Jiemian3 extends JFrame{ //定义组件
JButton[] an = {null,null,null,null,null,null,null,null}; public static void main(String[] args){
//运行本类的构造方法
Jiemian3 jiemian = new Jiemian3(); } public Jiemian3(){ //创建按钮
an[0] = new JButton("话梅");
an[1] = new JButton("果铺");
an[2] = new JButton("薯片");
an[3] = new JButton("饼干");
an[4] = new JButton("巧克力");
an[5] = new JButton("腰果");
an[6] = new JButton("锅巴");
an[7] = new JButton("开心果"); //网格布局管理器声明
//第一个参数是行,第二个参数是列,第三个参数是横间距,第四个参数是竖间距
this.setLayout(new GridLayout(3,3,15,15)); //添加按钮
this.add(an[0]);
this.add(an[1]);
this.add(an[2]);
this.add(an[3]);
this.add(an[4]);
this.add(an[5]);
this.add(an[6]);
this.add(an[7]); //设置窗口标题
this.setTitle("网格布局Gridlayout");
//设置窗口的宽高
this.setSize(300,300);
//设置窗口出现对于屏幕的位置
this.setLocation(100,100);
//禁止拉大拉小
this.setResizable(false);
//关闭窗口后释放资源
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//输出窗口
this.setVisible(true);
} }

//网格布局管理器import java.awt.*;import javax.swing.*;public class Jiemian3 extends JFrame{//定义组件JButton[]an={null,null,null,null,null,null,null,null};public static void main(String[] args){//运行本类的构造方法Jiemian3 jiemian=new Jiemian3();}public Jiemian3(){//创建按钮an[0]=new JButton("话梅");an[1]=new JButton("果铺");an[2]=new JButton("薯片");an[3]=new JButton("饼干");an[4]=new JButton("巧克力");an[5]=new JButton("腰果");an[6]=new JButton("锅巴");an[7]=new JButton("开心果");//网格布局管理器声明//第一个参数是行,第二个参数是列,第三个参数是横间距,第四个参数是竖间距this.setLayout(new GridLayout(3,3,15,15));//添加按钮this.add(an[0]);this.add(an[1]);this.add(an[2]);this.add(an[3]);this.add(an[4]);this.add(an[5]);this.add(an[6]);this.add(an[7]);//设置窗口标题this.setTitle("网格布局Gridlayout");//设置窗口的宽高this.setSize(300,300);//设置窗口出现对于屏幕的位置this.setLocation(100,100);//禁止拉大拉小this.setResizable(false);//关闭窗口后释放资源this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//输出窗口this.setVisible(true);}}

JAVA 网格布局管理器的更多相关文章

  1. java网格布局管理器

    public class GirdLayoutPosition extends JFrame{    public GirdLayoutPosition()    {        Container ...

  2. Java基础之创建窗口——使用网格布局管理器(TryGridLayout)

    控制台程序. 网格布局管理器可以在容器的矩形网格中布局组件. import javax.swing.*; import java.awt.*; import javax.swing.border.Et ...

  3. JAVA简单的网格布局管理器--JAVA基础

    网格布局管理器: GridLayoutDemo.java: import java.awt.GridLayout;import javax.swing.JButton;import javax.swi ...

  4. 编写Java程序,将JButton按钮按网格布局管理器格式放置

    返回本章节 返回作业目录 需求说明: 将JButton按钮按网格布局管理器格式放置 实现思路: 实现代码: public void init(){ setLayout(new GridLayout(4 ...

  5. java基础 布局管理器

    概念: 组建在容器(比如JFrame)中的位置和 大小 是由布局管理器来决定的.所有的容器都会使用一个布局管理器,通过它来自动进行组建的布局管理. 种类: java共提供了物种布局管理器:流式布局管理 ...

  6. JAVA GUI布局管理器

    边界布局管理器: a.布局方式:是把整个容器划分为五个部分.东西南北中,南北要贯通,中间最大 (不仅是中间的范围最大,权利也最大)当周边不存在的时候中间会占领周边,当中间不存在的时候周边不能占据中间 ...

  7. python之tkinter使用-Grid(网格)布局管理器

    # 使用tkinter编写登录窗口 # Grid(网格)布局管理器会将控件放置到一个二维的表格里,主控件被分割为一系列的行和列 # stricky设置对齐方式,参数N/S/W/E分别表示上.下.左.右 ...

  8. Java 的布局管理器GridBagLayout的使用方法(转)

    GridBagLayout是java里面最重要的布局管理器之一,可以做出很复杂的布局,可以说GridBagLayout是必须要学好的的, GridBagLayout 类是一个灵活的布局管理器,它不要求 ...

  9. 5、Java Swing布局管理器(FlowLayout、BorderLayout、CardLayout、BoxLayout、GirdBagLayout 和 GirdLayout)

    5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小而相应改变,不变的只是其相对位置,布局管理器比较难以控制,一般只在界面大小需要改是才用,但即使这 ...

随机推荐

  1. 使用JavaScript实现一个倒数计时程序

    使用JavaScript在网页中实现一个计算当年还剩多少时间的倒数计时程序,网页上能够实时动态显示“XX年还剩XX天XX时XX分XX秒”: 程序代码如下: <meta charset=" ...

  2. Oracle数据库——基本操作

    一.涉及内容 1.掌握Oracle 10g 相关服务的启动.停止. 2.熟练掌握数据库配置助手(DBA).企业管理器(OEM).SQL*Plus等工具的使用. 3.掌握使用STARTUP和SHUTDO ...

  3. linux包之iproute之ss命令

    概述 [root@localhost ~]# rpm -qa|grep iprouteiproute-2.6.32-31.el6.x86_64 当服务器的socket连接数量变得非常大时,无论是使用n ...

  4. OpenJudge就算概论-过滤多余的空格

    /*===================================== 过滤多余的空格 总时间限制: 1000ms 内存限制: 65536kB 描述 一个句子的每个单词之间也许有多个空格,过滤 ...

  5. OpenJudge计算概论-完美立方【暂时就想到了枚举法了】

    /*===================================== 完美立方 总时间限制: 1000ms 内存限制: 65536kB 描述 a的立方 = b的立方 + c的立方 + d的立 ...

  6. kaptcha随机验证码的使用详解,超实用

    效果图: 官方地址:https://code.google.com/p/kaptcha/w/list 1.把下载的kaptcha-2.3.2.jar添加到lib中 2.配置web.xml增加servl ...

  7. C++ 拆分字符串-copy()

    c++拆分字符串方法: #include <iostream>#include <string>#include <sstream>#include <alg ...

  8. redis配置文件解析

    Redis是一个简单高效的内存KV数据库,基本上下载源码make install,编译完成,然后进入src目录运行redis-server即可运行.就是因为这么简单往往有朋友直接运行,将没有密码的re ...

  9. AndroidStudio 应用(一)

    1.下载安装,用上vpn了都: 2.配置模拟器,出现问题:VT-x is disabled in the BIOS for both all CPU modes (VERR_VMX_MSR_ALL_V ...

  10. 图片上传,图片剪切jquery.imgareaselect

    ---恢复内容开始--- <%@ page language="java" contentType="text/html; charset=UTF-8" ...