'JOptionPane not working with ellipse function

I don't think there is any problem with code, but somehow it is not showing the ellipse before the loop is done.

my code is:

import javax.swing.JOptionPane;

void setup() {
  size(500, 500);
  background(255);
}

void draw() {
  for (int i = 0; i<5; i++) {
    JOptionPane.showMessageDialog(null, "you win!");
    ellipse(150, 150, 150, 150);
    delay(3000);
  }
}

thanks for your help in advance



Solution 1:[1]

You won't see changes to the screen until the draw() function completes. Your code loops 5 times with a 3 second delay each time draw() runs, so you'll only see the screen update with the ellipse every 15 seconds. JOptionPane is not the problem.

You should restructure your code to allow draw() to update the screen normally. It's hard to suggest how to do that with your example because I'm not sure what your code is trying to do.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cadin