Hi, I need help with drawing an ellipse that is bounded by the window it is drawn in. I have to use the Ellipse2D API.
Maybe I'm overlooking something but I can't seem to get the circle to fit the window. This is what i have so far:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import javax.swing.JComponent;
public class DrawEllipseComponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
Ellipse2D.Double ellipse = new Ellipse2D.Double(0,0,200,300);
g2.draw(ellipse);
g2.setColor(Color.GREEN);
g2.fill(ellipse);
}
}
import javax.swing.JFrame;
public class DrawEllipse
{
public static void main(String[] args)
{
DrawEllipseComponent ellipse = new DrawEllipseComponent();
JFrame frame = new JFrame();
frame.setSize(300, 400);
frame.setTitle("An Ellipse");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(ellipse);
frame.setVisible(true);
}
}