Why does this while loop prevent paint method from working correctly?

后端 未结 1 1051
失恋的感觉
失恋的感觉 2021-01-27 01:10

Here\'s my code:

package javaapplication2;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class         


        
相关标签:
1条回答
  • 2021-01-27 02:06

    Because painting happens in the Event Dispatch Thread, and you're blocking it with your obvious infinite loop. This will prevent any further painting from happening, events from being processed, and anything else that happens inside the EDT.

    That's why you never perform long running operations on EDT, but use a SwingWorker or other mechanism instead.

    0 讨论(0)
提交回复
热议问题