首页
IT
登录
6mi
u
盘
搜
搜 索
IT
我的笔记 网格布局 GridLayout
我的笔记 网格布局 GridLayout
xiaoxiao
2021-04-14
31
import
java.awt.*;
import
javax.swing.*;
public
class
wangge
extends
JFrame {
JButton[]
an
={
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
};//添加一个JButton 按钮属性。
public
static
void
main(String[] args)
{
wangge
A
=
new
wangge();
}
public
wangge()
{
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(
"杏仁"
);
an
[8]=
new
JButton(
"开心果"
);
this
.setLayout(
new
GridLayout(3,3,2,2));
// 括号里的数字 代表的是 行,列 ,行空 ,列空
for
(
int
i=0;i<
an
.
length
;i++)
{
this
.add(
an
[i]);
}
this
.setTitle(
"网格布局GridLayout"
);
this
.setSize(380,200);
this
.setLocation(200,200);
this
.setResizable(
false
);
//
Resizable
可变的尺寸
this
.setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE
);
this
.setVisible(
true
);
// Visible 可视的
}
}
转载请注明原文地址: https://ju.6miu.com/read-669827.html
技术
最新回复
(
0
)