Repainting Continuously in Java

后端 未结 4 1716
南旧
南旧 2021-01-16 07:09

I have a Java program that uses threads. In my run method, I have:

public void run() {
    while(thread != null){
        repaint();
        System.out.print         


        
4条回答
  •  臣服心动
    2021-01-16 07:45

    Cal repaint from a Swing Timer. That will not block the GUI, and will happen at whatever interval specified in the timer. Of course, by the nature of Swing/AWT painting, if the timer is set to repeat too fast, calls to paint might be coalesced (effectively ignored).

    Also, make sure the method is an override using:

    @Override
    public void paintComponent(Graphics g){
    

提交回复
热议问题