[英]Why is this print line command executing twice?
I have the code below. 我有下面的代码。
It all works, but annoyingly, the print line command in the while
loop runs twice. 一切正常,但令人讨厌的是,
while
循环中的print line命令运行两次。 There is (and I have tested for it), only unique items in the queue, no duplicates. 有(我已经测试过),队列中只有唯一的项目,没有重复项。
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);
}
Appreciate the help. 感谢帮助。
That means the paint
method is being called twice, which is perfectly normal. 这意味着
paint
方法被调用两次,这是完全正常的。 The system can call paint
as many times as it wants, so you shouldn't perform any operation that might change the state of your program within that method. 系统可以根据需要多次调用
paint
,因此您不应执行任何可能会在该方法中更改程序状态的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.