File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes can't rotate ellipse after certain period of time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "can Watch "can New topic
Author

can't rotate ellipse after certain period of time

budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
i have written code which will rotate ellipse after a certain period of time :

here's the code


Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3908
    
  18

What about your code?

TellTheDetails please.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
ok i have made a custom component Block . The block starts a Timer which starts time . The Time class calls renderShape() method and that method calls repaint() .
At the paintComponent() i am changing the rotational angle by calling the rotate method . Now this is where the Rectangle should rotate .
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4952
    
    8

Never put any kind of business logic in a painting method override. You have absolutely no control over when and how often a painting method executes.


luck, db
There are no new questions, but there may be new answers.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3908
    
  18

It's because you rotate the graphical context by the same transformation, on every refresh. The graphical context is reset after a new call to paintComponent(). You need to use a variable to keep track of the total rotation so far. [edit] And as Darryl has said, you need to do this outside the paintComponent() method. Change the rotation in your Time class, for example.

Also:
- Why are your class fields not private?
- Why aren't you using layout managers?
- Why is onefourth actually three fourths?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: can't rotate ellipse after certain period of time
 
jQuery in Action, 3rd edition