0
JButton의 왼쪽 상단에 숫자 (2 차원 배열)를 넣어야합니다. 하지만, 배열의 topLeftNum 순서와 같지 않은 번호 순서 결과 (잘못된 순서)가 있습니다. 수가 같은 순서로 표시됩니다 있도록 만들려면 내 problem..ThanksJButton 2D 배열의 문제점
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);
}
감사합니다 ... 내 문제를 해결합니다. –
이 대답을 올바른 것으로 표시하십시오. –
@PaulSullivan : 질문을 한 사용자가 더 이상 존재하지 않습니다. 0_0 –