Hello!

I have one JApplet and JPanel on it. I have drawn a shape, actually a ball, on JPanel and I would like to make it move in circle (to make it rounding).

Can you explain me how to do that?

It would be very helpful for me.

Printable View

- 08-17-2010, 09:58 AMmneskovicMake shape rounding (moving in circle)
Hello!

I have one JApplet and JPanel on it. I have drawn a shape, actually a ball, on JPanel and I would like to make it move in circle (to make it rounding).

Can you explain me how to do that?

It would be very helpful for me. - 08-17-2010, 10:33 AMJosAH
- 08-17-2010, 10:58 AMmneskovic
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:

Code:`g.fillOval(50, 50, 20, 20);`

Best regards,

Milica - 08-17-2010, 12:55 PMJosAH
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 PMmneskovic
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? - 08-17-2010, 01:53 PMJosAH
- 08-17-2010, 02:08 PMmneskovic
Can you explain me how to put timer in thread?

I have been making timers like this:

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 PMJosAH
- 08-17-2010, 03:05 PMmneskovic
OK, thank you, I will take a look.

Greetings!