swing之gridlayout
阅读原文时间:2023年09月20日阅读:1

package gui1;

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

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

public class gridlayout1 extends JFrame{
JButton [] a={null,null,null,null,null,null,null,null};
public static void main(String[] args) {
// TODO Auto-generated method stub
gridlayout1 g1=new gridlayout1();
}
public gridlayout1()
{

a\[\]=new JButton("瓜子");  
a\[\]=new JButton("话梅");  
a\[\]=new JButton("西瓜");  
a\[\]=new JButton("草莓");  
a\[\]=new JButton("香蕉");  
a\[\]=new JButton("苹果");  
a\[\]=new JButton("栗子");  
a\[\]=new JButton("黄瓜");  
//a\[8\]=new JButton("葡萄");

this.setLayout(new GridLayout(,,,));//默认是边界布局,如果想变成其他布局,加上

this.add(a\[\]);  
this.add(a\[\]);  
this.add(a\[\]);  
this.add(a\[\]);  
this.add(a\[\]);  
this.add(a\[\]);  
this.add(a\[\]);  
this.add(a\[\]);

this.setTitle("网格布局gridlayout");  
this.setSize(,);  
this.setLocation(, );  
this.setResizable(true);  
this.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);  
this.setVisible(true);

     }  

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章