Drawing a circle in the middle of the frame.
Hi,
My problem is that i want to write a Java Application that draws a circle in the middle of the frame. The circle should be the biggest possible size for the frame width and height.
So far i have created a circle however i am unable to make the circle fit in the middle of the frame.
Any help? thanks
import javax.swing.JComponent;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
publicclass MaxCircleextends JComponent
{
publicvoid paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
Ellipse2D.Double circle =
new Ellipse2D.Double(5,10,50,50);
g2.draw(circle);
g2.setPaint(Color.red);
g2.fill(circle);
}
publicstaticvoid main(String[] args)
{
JFrame frame =new JFrame();
finalint FRAME_WIDTH = 300;
finalint FRAME_HEIGHT = 400;
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("MaxCircle");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MaxCircle component =new MaxCircle();
frame.add(component);
frame.setVisible(true);
}
}

