my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Rotating an ImageIcon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Rotating an ImageIcon" Watch "Rotating an ImageIcon" New topic

Rotating an ImageIcon

Keshan Pillay

Joined: May 21, 2008
Posts: 29
Hello Everyone! Thank you for taking the time to look at my thread.
I have an assignment to do on concurrency. That's fine, however I face an initial hurdle.

This assignment is based on the dining philosophers problem.
I can change the number of philosophers at present by changing the appropriate variable in the code. I'm supposed to rotate the
philosophers around the table so they all "face" the centre, but at present they all remain upright around the table.

The rotateImageIcon method is the one I need to implement. It is stated in the handout that it is called in the correct places, and that we just need to implement it. Initially it is empty, except for the return statement "return picture".
What is currently within the method is my attempt.

We were given a URL as a hint.
This is the URL

However I can't seem to make any headway =[ I would appreciate it if someone could please push me in the right direction =]

Here is my code, and thanks again =D

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2446
Well, your code doesn't look like the code from the example.

Did you download the example and text it? Was the image rotated? Why did you change the code?
Keshan Pillay

Joined: May 21, 2008
Posts: 29
Thank you for your reply. Actually, all the code I presented was given to us as a skeleton for the assignment. The everything was given, and certain
parts are missing.

// FOR YOU... (these are parts we need to complete)

rotateImageIcon is the method I had a go at completing. It hasn't seemed to worked.
Keshan Pillay

Joined: May 21, 2008
Posts: 29
oh! I got it! I changed "at.rotate(Math.toRadians(angle), w/2.0, h/2.0); " to

at.rotate(angle, w/2.0, h/2.0);

now it works!

only there are these vertical black boxes shadowing the original position of the icons =p
I agree. Here's the link:
subject: Rotating an ImageIcon
It's not a secret anymore!