返回本章節
返回作業目錄
需求說明:
將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);
}