Java JButton的二维数组问题

Java JButton的二维数组问题,java,arrays,2d,jbutton,Java,Arrays,2d,Jbutton,我需要把数字(2d数组)放在JButton的左上角。但是,我得到的数字结果顺序错误(颠倒),与数组topLeftNum顺序不同。如何使号码以相同的顺序显示?请帮我解决我的问题。谢谢 final int ROWS = 12; final int COLS = 12; final static int topLeftNum[][]= { {-1, 1, 0, 2, 0, 0, 3, -1, 4, 0, 5, 0}, {6, 0, 0, 0, -1, -1, 0, -1, -1,

我需要把数字(2d数组)放在JButton的左上角。但是,我得到的数字结果顺序错误(颠倒),与数组topLeftNum顺序不同。如何使号码以相同的顺序显示?请帮我解决我的问题。谢谢

final int ROWS = 12;

final int COLS = 12;

final static int topLeftNum[][]= {
    {-1, 1, 0, 2, 0, 0, 3, -1, 4, 0, 5, 0},
    {6, 0, 0, 0, -1, -1, 0, -1, -1, -1, 0, -1},
    {-1, 0, -1, 0, -1, 7, 0, 0, 8, -1, 0, -1},
    {9, 0, 0, 0, 10, -1, -1, -1, 11, 0, 0, -1},
    {0, -1, -1, 12, 0, 0, 13, -1, 0, -1, -1, -1},
    {0, -1, 14, -1, 0, -1, 0, -1, 15, 0, 0, 16},
    {17, 0, 0, 18, 0, -1, 19, 20, 0, -1, -1, 0},
    {0, -1, 0, 0, -1, 21, 0, 0, 0, -1, -1, 0},
    {22, 23, 0, 0, -1, 0, -1, 0, -1,24, 0, 0},
    {-1, 0, -1, 25, 0, 0, -1, 0, -1, 0, -1, -1},
    {26, 0, 0, -1, -1, 0, -1, 27, 0, 0, 0, -1},
    {-1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1}
    };

public static void main(String[] args){

  SwingUtilities.invokeLater(new Runnable() {
     public void run(){
           new Lat1();
      }
   });
}

public Lat1() {
  //d = f.getText();
  //answer = d.charAt(0);
  this.getContentPane().setLayout(new GridLayout(ROWS, COLS));
  for (int j=0; j<ROWS; j++) {
    for (int i=0; i<COLS; i++)  {
       this.getContentPane().add(new Box(i, //the boxes index
                (topLeftNum[j][i] < 0) ? Color.BLACK : Color.WHITE, //pick the color
                topLeftNum[j][i], //the topleft number
                (char)(65+i), //the char inside
                this), //the action listener for the button
                i); //the index to place it on the container
       }
    }
    this.pack();
    this.setVisible(true);
}
final int ROWS=12;
最终整数COLS=12;
最终静态int-topLeftNum[]]={
{-1, 1, 0, 2, 0, 0, 3, -1, 4, 0, 5, 0},
{6, 0, 0, 0, -1, -1, 0, -1, -1, -1, 0, -1},
{-1, 0, -1, 0, -1, 7, 0, 0, 8, -1, 0, -1},
{9, 0, 0, 0, 10, -1, -1, -1, 11, 0, 0, -1},
{0, -1, -1, 12, 0, 0, 13, -1, 0, -1, -1, -1},
{0, -1, 14, -1, 0, -1, 0, -1, 15, 0, 0, 16},
{17, 0, 0, 18, 0, -1, 19, 20, 0, -1, -1, 0},
{0, -1, 0, 0, -1, 21, 0, 0, 0, -1, -1, 0},
{22, 23, 0, 0, -1, 0, -1, 0, -1,24, 0, 0},
{-1, 0, -1, 25, 0, 0, -1, 0, -1, 0, -1, -1},
{26, 0, 0, -1, -1, 0, -1, 27, 0, 0, 0, -1},
{-1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1}
};
公共静态void main(字符串[]args){
SwingUtilities.invokeLater(新的Runnable(){
公开募捐{
新Lat1();
}
});
}
公共图书馆1(){
//d=f.getText();
//答案=d.charAt(0);
this.getContentPane().setLayout(新的GridLayout(行、列));
对于(int j=0;j
i) ;//将其放置在容器上的索引


这一行就是问题所在,删除“i”就可以了。

@PaulSullivan:问这个问题的用户已经不存在了0\u 0