title: Rotate an image in java by the specified angle
body: <p>Here's the function which draws a shape at the given coordinates: </p>
  
  <pre><code>public void drawTank(int x,int y){
     int h = 50;
     int w = 50;
  
     graphic.setColor(Color.darkGray);
     graphic.drawRect(x, y, h, w);
     graphic.fillRect(x, y, h, w);
     graphic.setColor(Color.GRAY);
     graphic.drawRect(x+50, y+20, 35, 10);
     graphic.fillRect(x+50, y+20, 35, 10);
  }
  </code></pre>
  
  <p>I want to add one more variable to the above function called 'angle', so that the image is also rotated by the angle specified (drawTank(int x,int y,int angle).</p>
  
  <p><strong>Updated with example</strong></p>
  
  <p>What I tried to do is that I initialized Graphics2D and changed my code respectively:</p>
  
  <pre><code>g2D.setColor(Color.darkGray);
  g2D.drawRect(x, y, h, w);
  g2D.fillRect(x, y, h, w);
  g2D.setColor(Color.red);
  g2D.drawRect(x+50, y+20, 35, 10);
  g2D.fillRect(x+50, y+20, 35, 10);
  g2D.rotate((Math.toRadians(angle)));
  </code></pre>
  
  <p>But, this doesn't actually do anything. :/</p>