当我尝试在顶部涂有蓝色矩形的板上绘制矩形时,我看到矩形是在蓝色矩形下绘制的,但是在红色矩形之后调用了绘制红色矩形的方法。
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g); //To change body of generated methods, choose Tools | Templates.
//this method paints the blue board
pintarTablero(getGraphics(), tableroMio, 100, 200);
//red rectangle
g.setColor(Color.red);
g.drawRect(200, 200, 200, 200);
g.fillRect(200, 200, 200, 200);
}
public void pintarTablero(Graphics g, int tab[][], int x, int y) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (tab[i][j] == 0) {
// g.setColor(Color.blue);
//g.fillRect(x + i * 30, y + j * 30, 30, 30);
// g.setColor(Color.black);
g.drawRect(x + i * 30, y + j * 30, 30, 30);
}
}
}
}