Can I make a smooth circle that is constructing itself without a "wobbly" effect using Graphics2D? If yes, how? To understand what I mean you have to run the following example:
import java.awt.Color;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.*;
public class CircleExample {
static int angle = 0;
public static void main(String[] args) {
JFrame frame = new JFrame();
new Thread(new Runnable() {
public void run() {
while (true) {
if (angle >= 360) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
angle = 0;
}
angle++;
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
frame.repaint();
}
}
}).start();
frame.getContentPane().add(new Circle());
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
static class Circle extends JPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D gg = (Graphics2D) g;
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gg.setColor(Color.BLACK);
gg.drawArc(40, 40, 100, 100, 0, angle);
}
}
}