我正在编写一个程序,它有一个 9x9 按钮,每个按钮从左上角开始从 1 到 81 到右边
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MS extends JFrame implements ActionListener {
static JFrame bframe;
static JPanel p;
public MS() {
p = new JPanel(new GridLayout(9,9));
private static JButton[][] jgo = new JButton[9][9];
int count = 1;
for(int row=0; row < 9; row++)
for(int col=0; col < col; col++) {
jgo[row][col] = new JButton("%d",count);
p.add(jgo[row][col]);
count++;
}
}
public static void main(String[] args) {
bframe=new MS(); //CREATE me and
bframe.add(p); //add the JPanel
bframe.setSize(810,810);
bframe.setLocation(0,0); //where my upper left hand corner goes
bframe.setVisible(true); //I start out invisible
bframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //need this for the window manager
}
}
我的错误发生在我的构造函数中,它与我如何制作按钮和设置值有关。