我想写一个方法,创建一个空矩形,其中有另一个白色矩形,由一条线条图案包围(包含在for循环中)。
每当运行该方法时,我在循环的第一行得到一个零点异常。
我无法解决正在发生的事情......请帮忙。
public void displayArea () {
Graphics g = chartPanel.getGraphics();
int Xpos = 30;
int Ypos = 50;
int displayWidth = 300;
int displayHeight = 280;
int borderPatternY = 10;
int borderPatternX = 10;
for (int count = 0; borderPatternY <= 300 || borderPatternX <= 280; count++){
g.drawLine(30, borderPatternY, 330, borderPatternY);
g.drawLine(borderPatternX, 50, borderPatternX, 320);
borderPatternX = borderPatternX + 10;
borderPatternY = borderPatternY + 10;
}
g.setColor(Color.white);
g.fillRect(Xpos + 10, Ypos + 10, displayWidth-10, displayHeight -10);
g.setColor(Color.black);
g.drawLine(Xpos, 60, Xpos + displayWidth, 60);
g.drawLine(Xpos, 120, Xpos + displayWidth, 120);
g.drawLine(Xpos, 180, Xpos + displayWidth, 180);
g.drawLine(Xpos, 240, Xpos + displayWidth, 240);
}