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);

}

}

[2035 byte] By [Disco_Stua] at [2007-11-26 17:38:54]
# 1
What's wrong with this:g.setColor(Color.red);g.fillOval(0, 0, getWidth(), getHeight());And in the future, Swing questions should be posted in the Swing forum.
CaptainMorgan08a at 2007-7-9 0:07:04 > top of Java-index,Java Essentials,New To Java...