I'm drawing a circle in JPanel and using Swing Timer to update x,y co-ordinates of the circle.
How to move the circle in circular path.
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
g2d.setColor(Color.RED);
Shape planet = new Ellipse2D.Double(x, y, 20, 20);
g2d.fill(planet);
g2d.dispose();
}
public void actionPerformed(ActionEvent evt) {
double R = 200;
for (double t = 0; t < 2 * Math.PI; t += 0.01) {
x = R * Math.cos(t) + 0;
y = R * Math.sin(t) + 0;
revalidate();
repaint();
}
}