Here's the function which draws a shape at the given coordinates:
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);
}
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).
Updated with example
What I tried to do is that I initialized Graphics2D and changed my code respectively:
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)));
But, this doesn't actually do anything. :/