Results 1 to 9 of 9
- 08-17-2010, 09:58 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
- 08-17-2010, 10:33 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 08-17-2010, 10:58 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
OK, I understood explanation. Thank you very much for that.
I don't know how to code that. I have drawn a shape in paintComponent method like this:
Where and how to deal with the moving part?Java Code:g.fillOval(50, 50, 20, 20);
Best regards,
Milica
- 08-17-2010, 12:55 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Assume the circle's midpoint is the origin (0, 0); the midpoint of the ball makes a circular movement over a cirlce with radius R-r, so every point can be described as x= (R-r)*cos(phi), y= (R-r)*sin(phi) for any value of phi in [0, 2*PI).
You don't want to know where the midpoint of the ball is, you want to know the top left position of the bounding square; if the midpoint of the ball is at position (x, y) (see above) then the top left point of the bounding rectangle is at position (x-(R-r), y-(R-r))
The variable phi serves as a loop counter.
kind regards,
Jos
- 08-17-2010, 01:25 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Thank you very much for this explanation.
Should I use timer for this moving (to put that loop's code in it) or something similar?Last edited by mneskovic; 08-17-2010 at 01:28 PM.
- 08-17-2010, 01:53 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 08-17-2010, 02:08 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Can you explain me how to put timer in thread?
I have been making timers like this:
and then I call variable x1 in paintComponent method and start timer in button defined to start it.Java Code:timer1 = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent e) { x1++; PanelName.this.repaint(); }});
I would like to stop delays in timer, but if I put 0 instead of 500 it doesn't work well.
How to do that?
- 08-17-2010, 02:16 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 08-17-2010, 03:05 PM #9
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Similar Threads
-
how to change the shape of the JFrame to a oval shape
By kiki2009 in forum Java 2DReplies: 1Last Post: 04-02-2010, 12:48 PM -
Hey Guys I need some help with rounding...
By blueduiker in forum New To JavaReplies: 8Last Post: 12-08-2009, 08:58 AM -
Rounding
By Moncleared in forum New To JavaReplies: 2Last Post: 11-17-2009, 08:16 AM -
Need help rounding. =/
By yo1mcool in forum New To JavaReplies: 1Last Post: 10-07-2008, 05:02 AM -
Help with java Rounding
By silvia in forum New To JavaReplies: 1Last Post: 07-20-2007, 07:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks