2015-04-23 40 views
2

我是一個初學Java程序員,我有一個把圖像放在我的java遊戲中的問題。在我的代碼中,我使用了f,但是我想用標誌圖像來改變它。

如何使用drawImage?在java中使用drawImage圖像

protected void paintComponent(Graphics graphics) { 

     removeAll(); 

     super.paintComponent(graphics); 

     if (caseModele.contientFlag()) { 

      setBackground(Color.WHITE); 

      graphics.setColor(Color.blue); 
      graphics.drawString("f", getWidth()/2, getHeight()/2);//here 

     } 
} 
+0

有一點需要注意:drawString是左下角的錨定,而drawImage是左上角的錨點:您的字符串將打印y組件到drawString參數,而您的圖像將被繪製在y參數的下方 – ControlAltDel

回答