Why is this print line command executed twice?

I have the code below.

Everything works, but annoyingly, the print line command whileis executed twice in a loop . There is (and I tested 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);
}

Rate the help.

+3
source share
1 answer

This means that the method paintis called twice, which is completely normal. The system can call paintas many times as it wants, so you should not perform any operation that could change the state of your program in this method.

+6
source

Source: https://habr.com/ru/post/1796505/


All Articles