为什么这个打印行命令执行两次? [英] Why is this print line command executing twice?

查看:121
本文介绍了为什么这个打印行命令执行两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码。



这一切都有效,但令人烦恼的是,在中的打印行命令循环运行两次。有(我已经测试过),只有队列中的唯一项目,没有重复。

  public void paint(Graphics g){

boolean isParent;

int drawCount = 1;

int x = 0,y = 0,width = 0,height = 0;
颜色的颜色; (!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;
color = getRectangleColour(drawNode);
System.out.println(drawCount +。Drawing:x =+ x +; y =+ y +
; width =+ width +; height =+ height +
; color =+ colour.toString());
minMax(drawNode);
g.setColor(color);
g.fillRect(x,y,width,height);
drawCount ++;

$ b System.out.println(树的最小级别:+ min +\\\
最高级别:+ max);

欣赏帮助。

paint 方法被调用两次,这是非常正常的。系统可以根据需要多次调用 paint ,所以不应该执行任何可能会改变程序状态的操作。


I have the code below.

It all works, but annoyingly, the print line command in the while loop runs twice. 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. 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.

这篇关于为什么这个打印行命令执行两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆