0

I am attempting to recreate Wheel of Fortune in Java. What I have been thinking about doing is creating a wheel, and rotating the image and randomly stopping. But, I don't know how to rotate a JLabel. I am using NetBeans JFrame creator.

I can't really provide code, as this is just a concept in my head right now. I am planning to set the JLabel's icon to the wheel. I need to be able to rotate a JLabel at a button press, and stop at random. It then, needs to read the rotation value of the JLabel, so it can read the amount of points you win. Is this possible?

Yes, I have researched. All the other rotating JLabel forums do not show how to read the rotation value.

I am a beginner in Java. Any help is appreciated! :)

Brennan B.
  • 11
  • 7
  • *"All the other rotating JLabel forums do not show how to read the rotation value."* You need to have that stored in the model, not the view. Have a class called `Prizes` or whatever you want to call it, where you have the text for each Prize (i.e. the points) and you could have an `angle` variable to know what's its angle... Then on the view just paint the rotation – Frakcool Feb 10 '17 at 19:47
  • Rotating controls is a pain in the code, it can be done [for example](http://stackoverflow.com/questions/22976226/is-there-any-way-i-can-rotate-this-90-degrees/22976755#22976755) and [example](http://stackoverflow.com/questions/25252127/java-rotating-non-square-jpanel-component/25253453#25253453) – MadProgrammer Feb 10 '17 at 20:41
  • You'd actually be better going down a "custom painting" route, for [example](http://stackoverflow.com/questions/15779877/rotate-bufferedimage-inside-jpanel/15780090#15780090), [example](http://stackoverflow.com/questions/20367149/how-to-use-affinetransform-quadrantrotate-to-rotate-a-bitmap/20368979#20368979), [example](http://stackoverflow.com/questions/12964983/rotate-image-around-character-java/12971987#12971987) – MadProgrammer Feb 10 '17 at 20:42

1 Answers1

1

I am planning to set the JLabel's icon to the wheel. I need to be able to rotate a JLabel at a button press

Don't rotate the label, instead you can just rotate the Icon.

Check out Rotated Icon. You just specify the angle of rotation and it will paint the Icon rotated. You can use the getDegrees() method to know the current rotation at any time.

camickr
  • 321,443
  • 19
  • 166
  • 288