java为什么这个打印行命令要执行两次?
我有下面的代码
这一切都可以工作,但令人烦恼的是,while
循环中的print line命令运行了两次。队列中只有唯一的项(我已经测试过了),没有重复项
public void paint(Graphics g) {
boolean isParent;
int drawCount = 1;
int x = 0, y = 0, width = 0, height = 0;
Color colour;
while (!qtreeQueue.empty()) {
drawNode = (QuadTreeNode) qtreeQueue.deque();
isParent = drawNode.getIsParent();
if (!isParent) {
x = drawNode.getRectangle().x;
y = drawNode.getRectangle().y;
width = drawNode.getRectangle().width;
height = drawNode.getRectangle().height;
colour = getRectangleColour(drawNode);
System.out.println(drawCount + ". Drawing: x = " + x + "; y = " + y +
"; width = " + width + "; height = " + height +
"; colour = " + colour.toString());
minMax(drawNode);
g.setColor(colour);
g.fillRect(x, y, width, height);
drawCount++;
}
}
System.out.println("Minimum level of tree: " + min + "\nMaximum level: " + max);
}
谢谢你的帮助
# 1 楼答案
这意味着
paint
方法被调用了两次,这是完全正常的。系统可以调用paint
任意次数,因此您不应该在该方法中执行任何可能更改程序状态的操作