Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

like image 214
Alex Avatar asked Mar 22 '26 17:03

Alex


1 Answers

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.

like image 134
casablanca Avatar answered Mar 25 '26 07:03

casablanca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!