import java.awt.*;
public class jtest {
JButton btn[][];
JFrame mainFrame;
JPanel panel;
public jtest() {
panel = new JPanel(new GridLayout(3, 3));
btn = new JButton[3][3];
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; 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();
}
沒有留言:
張貼留言