1

6x6 の「テーブル」をクリアするにはどうすればよいですか? (すでにActionListenerでclearbuttonを作成しました...など)

        //other code above that creates window, below is the code that creates the table I need to clear

         square = new JTextField[s][s];
    for (int r=0; r!=s; r++) {
        symbols[r] = new JTextField();
        symbols[r].setBounds(35+r*35, 40, 30, 25);
        win.add(symbols[r], 0);
        for (int c=0; c!=s; c++) {
            square[r][c] = new JTextField();
            square[r][c].setBounds(15+c*35, 110+r*30, 30, 25);
            win.add(square[r][c], 0);
        }
    }
    win.repaint();
}
4

3 に答える 3

1

配列をループし、各要素を null に設定します。java.utils.Arraysユーティリティ クラスを使用して、物事をよりクリーン/クリーンにすることができます。

for( int i = 0; i < square.length; i++ )
   Arrays.fill( square[i], null );
于 2012-10-18T02:12:32.663 に答える
0

何かのようなもの...

for (int index = 0; index < square.length; index++) {
    square[index] = null;
}
square = null;

トリックよりも多くのことを行います(実際、通常は最後の行で十分です)...

あなたが本当にパラノイアなら...

for (int index = 0; index < square.length; index++) {
    for (int inner = 0; inner < square[index].length; inner++) {
        square[index][inner] = null;
    }
    square[index] = null;
}
square = null;
于 2012-10-18T01:16:29.067 に答える