1

I am currently making a game with Java. I added an image to the screen using a JLabel and I want to know how to rotate it. I have done a lot of research but have not found anything useful. Can I have some help? Here is my code:

(Code from first class)

public static ImageIcon image = new ImageIcon("Images/unnamed.png");
public static JLabel label = new JLabel("", image, JLabel.CENTER);

(Code from second class)

Main.label.setBounds(Game.birdX, Game.birdY, Game.birdWidth, Game.birdWidth);
add(Main.label);

Sorry if I am doing something wrong on this website, it's one of my first times using it. Also, I have only been coding Java for 2 weeks now.

Ben Jamin
  • 35
  • 6
  • Take a look at this [thread](http://stackoverflow.com/questions/43958482/how-do-i-align-components-in-java-swing) – Fady Saad May 13 '17 at 22:21

1 Answers1

0

One way is to use the Rotated Icon.

You just specify the degrees of rotation and a new Icon will be created for you.

Also, don't use static variable. This suggests improper design. The icon and label should just be instance variables in the class where you use them.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • I read the tutorial on the RotatedIcon and created a class for it. I still find it a bit confusing though. How would I make a new RotatedIcon that rotates the image to a specific degree? Thanks. – Ben Jamin May 13 '17 at 22:58
  • Yeah I saw it I just used it the wrong way. I just figured out my mistake a couple minutes ago. Thanks anyways. – Ben Jamin May 13 '17 at 23:28