2017-04-27 197 views
0

在我的程序中,我创建了一个程序,其中二进制数字下降,玩家必须在击中地面之前键入正确的值。但是,除非您通过单击并拖动并调整框架大小调整游戏屏幕,否则重新绘制调用不起作用。重画不更新游戏画面

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(); 

    } 
} 

在节目桂延伸的JFrame和GameControlGui扩展JPanel

任何帮助,将不胜感激!谢谢

+0

要么你有一个引用问题或一个线程阻塞问题,但它是不可能从上下文代码 – MadProgrammer

+0

中得知更好的帮助,发布一个[MCVE]或[Short,Self Contained,Correct Example](http: //www.sscce.org/)。 –

回答

0

repaint()调用paintComponent。我不确定你的paintComponent里面有什么,这是说,很难说没有看到你所有的代码是什么问题。