public class Example implements EntryPoint {
AbsolutePanel absolutePanel =new AbsolutePanel();
Button reset = new Button("Reset");
Button[][] buttons = new Button[20][20];
Grid grid = new Grid();
public Example(){
absolutePanel.setSize("400","400");
absolutePanel.add(reset);
grid = new Grid(20,20);
for (int i = 0; i < buttons.length; i++) {
for (int j = 0; j < buttons.length; j++) {
buttons[i][j] = new Button();
grid.setWidget(20,20,buttons[i][j]);
}
}
absolutePanel.add(grid);
}
public void onModuleLoad() {
// startGame(9,9,10);
RootPanel.get().add(absolutePanel);
}
Button[][] buttons = new Button[20][20];
这样buttons.length=400,你for循环中肯定越界了
如何 修改呀 我要做一個 掃雷的遊戲.. 應該怎麼改呢 謝謝你了
第二个for循环使用for (int j = 0; j < buttons[i].length; j++) {
private static final int BTN_COLS = 20;
private static final int BTN_ROWS = 20;
Button[][] buttons = new Button[BTN_ROWS][BTN_COLS];
...
for (int i = 0; i < BTN_ROWS; i++) {
for (int j = 0; j < BTN_COLS; j++) {