idWidth, y + gridHeight, gridWidth, gridHeight);
if (width > height) {
mydrawRect(x + gridWidth * 2, y, gridWidth, gridHeight);
mydrawRect(x + gridWidth * 2, y + gridHeight, gridWidth, gridHeight);
//最右边的竖线
DrawChessman(x + gridWidth * 3, y);
DrawChessman(x + gridWidth * 3, y + gridHeight);
DrawChessman(x + gridWidth * 3, y + gridHeight * 2);
//最下面的横线
DrawChessman(x, y + gridHeight * 2);
DrawChessman(x + gridWidth, y + gridHeight * 2);
DrawChessman(x + gridWidth * 2, y + gridHeight * 2);
}
else {
mydrawRect(x, y + gridHeight * 2, gridWidth, gridHeight);
mydrawRect(x + gridWidth, y + gridHeight * 2, gridWidth, gridHeight);
//最右边的竖线
DrawChessman(x + gridWidth * 2, y);
DrawChessman(x + gridWidth * 2, y + gridHeight);
DrawChessman(x + gridWidth * 2, y + gridHeight * 2);
DrawChessman(x + gridWidth * 2, y + gridHeight * 3);
//最下面的横线
DrawChessman(x, y + gridHeight * 3);
DrawChessman(x + gridWidth, y + gridHeight * 3);
}
//画光标
gg.setColor(focusColor);
gg.drawLine(currentX, currentY,currentX + gridWidth /5, currentY);
gg.drawLine(currentX, currentY, currentX,currentY + gridHeight /5);
gg.drawLine(currentX +gridWidth*4/5,currentY,currentX + gridWidth, currentY);
gg.drawLine(currentX + gridWidth, currentY, currentX + gridWidth,currentY + gridHeight /5);
gg.drawLine(currentX,currentY + gridHeight * 4/ 5,currentX, currentY + gridHeight);
gg.drawLine(currentX,currentY + gridHeight,currentX + gridWidth / 5,currentY + gridHeight);
gg.drawLine(currentX +gridWidth*4/5,currentY + gridHeight, currentX + gridWidth,currentY + gridHeight);
gg.drawLine(currentX + gridWidth,currentY + gridHeight *4 / 5,currentX + gridWidth, currentY + gridHeight);
repaint();
}
catch (Exception e) {
System.out.println("moveFoucs Error:" + e);
}
}
/*
* 画格子,并画棋子。把这部分独立出来主要是要检查边界问题
* x格子右上角x
* y格子右上角y
* width格子宽度
* height格子高度
*/
private void mydrawRect(int x, int y, int width, int height) {
int a, b;
a = (x - baseX) / gridWidth + 1;
b = (y - baseY) / gridHeight + 1;
if (a != lineNumber && b != lineNumber) {
gg.setColor(lineColor);
gg.drawRect(x, y + 1, width, height);
}
DrawChessman(x, y);
}
//画棋子,x,y分别是圆的中心坐标,棋子的直径为格子边长(格子为正方形)的4/5
public void DrawChessman(int x, int y) {
try {
int a;
int b;
a = (x - baseX) / gridWidth + 1;