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

返回本章节

返回作业目录


需求说明:

将JButton按钮按网格布局管理器格式放置

实现思路:

实现代码:

public void init(){
	setLayout(new GridLayout(4, 4));
	setFont(new Font("Times New Roman", Font.BOLD, 24));
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			int k=i*4+j;
			add(new JButton(""+k));
		}
	}
	this.setSize(450,300);
	this.setVisible(true);
}

 

猜你喜欢

转载自blog.csdn.net/weixin_44893902/article/details/106793325
今日推荐