draw circle java code example
Example 1: awt draw circle
public void drawCenteredCircle(Graphics2D g, int x, int y, int r) {
x = x-(r/2);
y = y-(r/2);
g.fillOval(x,y,r,r);
}
Example 2: java create circle
ellipse(0, 0, 100, 100);
Example 3: draw circle in java
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class DrawCircle extends Frame
{
Shape circle=new Ellipse2D.Float(100.0f,100.0f,100.0f,100.0f);
public void paint(Graphics g)
{
Graphics2D ga=(Graphics2D)g;
ga.draw(circle);
ga.setPaint(Color.blue);
ga.fill(circle);
}
public static void main(String args[])
{
Frame frame=new DrawCircle();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
frame.setSize(300, 250);
frame.setVisible(true);
}
}
Example 4: how to draw a circle in java swing
g.drawOval(50,50,100,100);