Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't rotate ellipse after certain period of time

 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have written code which will rotate ellipse after a certain period of time :

here's the code


 
Stephan van Hulst
Bartender
Pie
Posts: 5790
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about your code?

TellTheDetails please.
 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stephan van Hulst
Bartender
Pie
Posts: 5790
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic