在java中的方法中使用特定索引处的数组
我正在做一个名为Light out的游戏!我想创建一个方法,在某个索引处更改按钮的颜色。为此,我使用了以下代码:
Color bg = _buttons[x][y].getBackground();
if(bg.equals(Color.white)){
_buttons[x][y].setBackground(Color.yellow);
}
else if (bg.equals(Color.yellow)){
_buttons[x][y].setBackground(Color.white);
x和y是整数,它们是我看到的当前值。 基本上,我想做一个方法,无论我在什么索引。我试过了
public void flipIt(JButton _buttons[this] [this]){
Color bg = _buttons[this][this].getBackground();
}
但是java不喜欢这样,有人能给我指出正确的方向吗
# 1 楼答案
在呼叫代码中,您可以执行以下操作:
你的函数是这样的