简体   繁体   English

重新绘制不会更新游戏屏幕

[英]Repaint Doesnt update the game screen

In my program, I am creating a program where binary numbers fall down and players have to type in the correct value before it hits the ground. 在我的程序中,我正在创建一个程序,在该程序中二进制数会下降,并且玩家必须输入正确的值才可以使用。 However, the repaint call does not take affect UNLESS you resize the game screen by clicking and dragging it and resizing the frame. 但是,重新绘制调用不会生效,除非您通过单击并拖动并调整框架的大小来调整游戏屏幕的大小。

  public void run() {
    boolean debug = true;
    if (debug) {
        System.out.println("run debugging output enabled");
        System.out.println("time: " + time);
    }
    previousTime = time;
    time = System.currentTimeMillis();
    while (running) {
        previousTime = time;
        time = System.currentTimeMillis();
        for (Number n : numbers.values()) {
            n.update(time - previousTime);
        }
        if (debug)
            System.out.println("new time: " + time + "\n time difference: " + (time - previousTime));
        try{
            Thread.sleep(300);
        }
        catch(Exception e){

        }
        gui.getGameControl().repaint();

    }
}

In the program Gui extends JFrame and GameControlGui extends JPanel 在程序中,Gui扩展了JFrame,GameControlGui扩展了JPanel

Any help would be much appreciated! 任何帮助将非常感激! Thank you 谢谢

repaint() calls the paintComponent . repaint()调用paintComponent I'm not sure what is inside your paintComponent , that being said it's hard to say what the problem is without seeing all of your code. 我不确定paintComponent内是什么,也就是说如果不查看所有代码就很难说出问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM