Java game loop (painting) freezes my window

后端 未结 3 1630
名媛妹妹
名媛妹妹 2020-11-28 16:48

I\'m changing \"views\" with cardLayout (this class has a JFrame variable). When a user clicks a new game button this happens:

public class View         


        
3条回答
  •  清歌不尽
    2020-11-28 17:20

    What does update do? You probably shouldnt call game.loop() on the EDT. You are running a loop on EDT, your repaint wont ever be invoked since repaint queues an event on EDT and it seems kind busy. Try moving game.loop() to another thread

    new Thread(new Runnable() {
        @override
        public void run() {
            game.loop();
        }
    }).start();
    

    This way you wont block the EDT while the repaint still gets to be executed on the EDT.

提交回复
热议问题