2017-04-27 42 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裏面有什麼,這是說,很難說沒有看到你所有的代碼是什麼問題。