1.
import javax.swing.*;
import java.awt.*;
public class jtest {
JButton btn[][];
JFrame mainFrame;
JPanel panel;
public jtest() {
panel = new JPanel(new GridLayout(8, 8));
btn = new JButton[8][8];
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
//產生JButton實體物件
btn[x][y] = new JButton(x + "," + y);
panel.add(btn[x][y]);
}
}
mainFrame = new JFrame("JButton Array");
mainFrame.getContentPane().add(panel);
mainFrame.pack();
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new jtest();
}
}
2.完成圖
沒有留言:
張貼留言