以下代码包含被覆盖以制作矩形图案的方法。我想为每个矩形赋予不同的颜色。你知道如何做到这一点吗?
public void actionPerformed(ActionEvent event) {
int x1 = 60;
int y1 = 60;
int width = 280;
int length = 140;
Graphics paper = panelForBackGround.getGraphics();
for (int x = 1; x < 8; x++) {
paper.draw3DRect(x1, y1, width,length, true);
x1 = x1 + 10;
y1 = y1 + 10;
width = width - 20;
length = length - 20;
}