我正在做一项跳棋作业,即使我把它设置成只使相应的米色变成绿色,角落的部分仍然会使棕色的部分发光,如下所示:
http://i.stack.imgur.com/SFggh.png
这是它的代码:
for(int x=0; x<64; x++)
{
if (e.getSource()==board[x] && board[x].getText().equals("0") && board[x].getForeground().equals(Color.WHITE))
{
board[x].setBackground(Color.YELLOW);
board[x-7].setBackground(Color.GREEN);
board[x-9].setBackground(Color.GREEN);
clickSteps=2;
}谢谢!
发布于 2015-01-18 22:36:04
如果您需要将board保持为一个单一维度,这可能有效(未经测试):
for(int x = 0; x < 64; x++) {
if(e.getSource() == board[x] &&
board[x].getText().equals("0") &&
board[x].getForeground().equals(Color.WHITE)) {
board[x].setBackground(Color.YELLOW);
int myPos = x % 8;
if(myPos < 7) {
// Up and to the right, only if we are not rightmost.
board[x-7].setBackground(Color.GREEN);
}
if(myPos > 0) {
// Up and to the left, only if we are not leftmost.
board[x-9].setBackground(Color.GREEN);
}
}
}https://stackoverflow.com/questions/28015552
复制相似问题